WooCommerce Code Reference

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:

  1. Use a group string to identify all objects of a type.
  2. Before setting cache, prefix the cache key by using the get_cache_prefix.
  3. 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()  : bool
Invalidate cache group.
generate_cache_prefix()  : string
Generate a cache-safe prefix value.
is_valid_cache_prefix()  : bool
Check whether a cached prefix can be used as a cache-key namespace.

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
stringPrefix.

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
stringPrefixed 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) : bool
Parameters
$group : string

Group of cache to clear.

Tags
since
3.9.0
Return values
boolTrue when the new prefix was persisted to the object cache, false otherwise.

generate_cache_prefix()

Generate a cache-safe prefix value.

private static generate_cache_prefix() : string
Return values
stringCache prefix.

is_valid_cache_prefix()

Check whether a cached prefix can be used as a cache-key namespace.

private static is_valid_cache_prefix(mixed $prefix) : bool
Parameters
$prefix : mixed

Cached prefix value.

Return values
boolTrue if the prefix is valid.