CacheNameSpaceTrait
Implements namespacing algorithm to simulate grouping and namespacing for wp_cache, memcache and other caching engines that don't support grouping natively.
See the algorithm details here: https://github.com/memcached/memcached/wiki/ProgrammingTricks#namespacing.
To use the namespacing algorithm in the CacheEngine class:
- Use a group string to identify all objects of a type.
- Before setting cache, prefix the cache key by using the
get_cache_prefix
. - Use
invalidate_cache_group
function to invalidate all caches in entire group at once.
Table of Contents
- get_cache_prefix() : string
- Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
- get_prefixed_key() : string
- Helper method to get prefixed key.
- incr_cache_prefix() : mixed
- Increment group cache prefix (invalidates cache).
- invalidate_cache_group() : mixed
- Invalidate cache group.
Methods
get_cache_prefix()
Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
public
static get_cache_prefix(string $group) : string
Parameters
- $group : string
-
Group of cache to get.
Return values
string — Prefix.get_prefixed_key()
Helper method to get prefixed key.
public
static get_prefixed_key(string $key, string $group) : string
Parameters
- $key : string
-
Key to prefix.
- $group : string
-
Group of cache to get.
Return values
string — Prefixed key.incr_cache_prefix()
Increment group cache prefix (invalidates cache).
public
static incr_cache_prefix(string $group) : mixed
Parameters
- $group : string
-
Group of cache to clear.
Return values
mixed —invalidate_cache_group()
Invalidate cache group.
public
static invalidate_cache_group(string $group) : mixed
Parameters
- $group : string
-
Group of cache to clear.