WooCommerce Code Reference

CacheEngine

Interface for cache engines used by objects inheriting from ObjectCache.

Here "object" means either an array or an actual PHP object.

Table of Contents

cache_object()  : bool
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_cached_object()  : array<string|int, mixed>|object|null
Retrieves an object cached under a given key.
is_cached()  : bool
Checks if an object is cached under a given key.

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
boolTrue if the object is cached successfully, false otherwise.

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
boolTrue 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
boolTrue if the object is removed from the cache successfully, false otherwise (because the object wasn't cached or for other reason).

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

They 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|nullThe cached object, or null if there's no object cached under the passed key.

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
boolTrue if there's an object cached under the given key, false otherwise.