WooCommerce Code Reference

WPCacheEngine
in package
implements CacheEngine Uses CacheNameSpaceTrait

Implementation of CacheEngine that uses the built-in WordPress cache.

Interfaces, Classes and Traits

CacheEngine
Interface for cache engines used by objects inheriting from ObjectCache.

Table of Contents

cache_object()  : bool
Caches an object under a given key, and with a given expiration.
cache_objects()  : array<string|int, mixed>
Caches an object under a given key, and with a given expiration.
delete_cache_group()  : bool
Deletes all cached objects under a given group.
delete_cached_object()  : bool
Removes a cached object from the cache.
get_cache_prefix()  : string
Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
get_cached_object()  : array<string|int, mixed>|object|null
Retrieves an object cached under a given key.
get_cached_objects()  : array<string|int, mixed>
Retrieves a set of objects cached under the given keys.
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.
is_cached()  : bool
Checks if an object is cached under a given key.
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

cache_object()

Caches an object under a given key, and with a given expiration.

public cache_object(string $key, array<string|int, mixed>|object $object, int $expiration[, string $group = '' ]) : bool
Parameters
$key : string

The key under which the object will be cached.

$object : array<string|int, mixed>|object

The object to cache.

$expiration : int

Expiration for the cached object, in seconds.

$group : string = ''

The group under which the object will be cached.

Return values
bool — True if the object is cached successfully, false otherwise.

cache_objects()

Caches an object under a given key, and with a given expiration.

public cache_objects(array<string|int, mixed> $objects, int $expiration[, string $group = '' ]) : array<string|int, mixed>
Parameters
$objects : array<string|int, mixed>

The objects to cache keyed by the key to cache under.

$expiration : int

Expiration for the cached object, in seconds.

$group : string = ''

The group under which the object will be cached.

Return values
array<string|int, mixed> — Array of return values, grouped by key. Each value is either true on success, or false on failure

delete_cache_group()

Deletes all cached objects under a given group.

public delete_cache_group([string $group = '' ]) : bool
Parameters
$group : string = ''

The group to delete.

Return values
bool — True if the group is deleted successfully, false otherwise.

delete_cached_object()

Removes a cached object from the cache.

public delete_cached_object(string $key[, string $group = '' ]) : bool
Parameters
$key : string

They key under which the object is cached.

$group : string = ''

The group under which the object is cached.

Return values
bool — True if the object is removed from the cache successfully, false otherwise (because the object wasn't cached or for other reason).

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_cached_object()

Retrieves an object cached under a given key.

public get_cached_object(string $key[, string $group = '' ]) : array<string|int, mixed>|object|null
Parameters
$key : string

The key under which the object to retrieve is cached.

$group : string = ''

The group under which the object is cached.

Return values
array<string|int, mixed>|object|null — The cached object, or null if there's no object cached under the passed key.

get_cached_objects()

Retrieves a set of objects cached under the given keys.

public get_cached_objects(array<string|int, string> $keys[, string $group = '' ]) : array<string|int, mixed>
Parameters
$keys : array<string|int, string>

The keys under which the object to retrieve is cached.

$group : string = ''

The group under which the object is cached.

Return values
array<string|int, mixed> — The cached array of objects keyed by the given keys, values will be null for any non-cached keys.

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

Group of cache to clear.

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

is_cached()

Checks if an object is cached under a given key.

public is_cached(string $key[, string $group = '' ]) : bool
Parameters
$key : string

The key to verify.

$group : string = ''

The group under which the object is cached.

Return values
bool — True if there's an object cached under the given key, false otherwise.

generate_cache_prefix()

Generate a cache-safe prefix value.

private static generate_cache_prefix() : string
Return values
string — Cache 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
bool — True if the prefix is valid.