Skip to content

Cache

Functions for reading, writing, and clearing the DMS object cache.

DMS caching wraps the WordPress object cache (wp_cache_*) with group-based namespacing. On sites with a persistent cache backend (Redis, Memcached), cache groups persist between requests. On sites without one, cache is per-request only.


Functions

dms_cache_get( int|string $key, string $group = 'dms', bool $force = false, bool $found = null ): mixed

Retrieves a value from the DMS cache. Returns false if the key is not found.

Parameters

Name Type Default Description
$key int\|string - Cache key
$group string 'dms' Cache group namespace
$force bool false Force a fresh fetch, bypassing the local cache
$found bool\|null null Passed by reference; set to true if the key was found

Returns - mixed - the cached value, or false if not found

Example

$data = dms_cache_get( 'my_key', 'my-plugin' );

if ( $data === false ) {
    $data = expensive_query();
    dms_cache_set( 'my_key', $data, 0, 'my-plugin' );
}

dms_cache_set( int|string $key, mixed $data, int $expire = 0, string $group = 'dms' ): bool

Stores a value in the DMS cache.

Parameters

Name Type Default Description
$key int\|string - Cache key
$data mixed - Value to cache
$expire int 0 Expiry in seconds. 0 means no expiry (until end of request or cache flush).
$group string 'dms' Cache group namespace

Returns - bool

Example

dms_cache_set( 'my_key', $data, HOUR_IN_SECONDS, 'my-plugin' );

dms_cache_delete( int|string $key, string $group = 'dms' ): void

Removes a specific key from the DMS cache.

Parameters

Name Type Default Description
$key int\|string - Cache key to delete
$group string 'dms' Cache group namespace

Returns - void

Example

dms_cache_delete( 'my_key', 'my-plugin' );

dms_cache_clear(): void

Clears all DMS caches and also triggers cache purges for common WordPress caching plugins and hosting environments (WP Rocket, LiteSpeed, WPEngine, SiteGround, W3 Total Cache, WP Super Cache, and others).

Returns - void

Example

dms_cache_clear();

dms_clear_post_cache( int $post_id ): void

Clears cached data associated with a single listing post.

Parameters

Name Type Default Description
$post_id int - The listing post ID

Returns - void

Example

dms_clear_post_cache( 42 );