CacheSupportPsr16
in package
implements
CacheInterface
PSR-16 adapter over the WordPress Object Cache (`wp_cache_*`), scoped to a single cache area (mapped to a `wp_cache` group). Persistent when a backend drop-in (Redis, Memcached) is installed; request-scoped otherwise.
The group is {groupPrefix}{area}. The prefix defaults to middaglib_, the
neutral library marker, which names no product; a consumer passes its own.
Allows platform-agnostic framework collaborators (e.g. the core cached item
repository decorator) to consume the WP object cache via CacheInterface
without depending on the (key, group) calling convention or WP statics.
WordPress counterpart of the Moodle adapter's CacheSupportPsr16.
Area purge without a portable wp_cache_flush_group(): WordPress exposes no
reliable per-group flush across every backend, so clear() bumps a
per-area generation counter kept inside the group. Every entry is stored under
a {generation}:{key} name, so a bump orphans the whole area at once without
touching other groups (unlike wp_cache_flush(), which nukes everything).
Table of Contents
Interfaces
- CacheInterface
Constants
- GENERATION_KEY : string = '__gen'
Properties
- $group : string
Methods
- __construct() : mixed
- clear() : bool
- Purge the whole area by bumping its generation; older entries become unreachable behind the new `{generation}:` prefix.
- delete() : bool
- deleteMultiple() : bool
- get() : mixed
- getMultiple() : iterable<string, mixed>
- has() : bool
- set() : bool
- setMultiple() : bool
- generation() : int
- Current generation for this area, initialised to 1 on first use.
- scopedKey() : string
- Prefix a caller key with the current area generation.
- ttlSeconds() : int
- Normalise a PSR-16 TTL to whole seconds (0 = no expiration).
Constants
GENERATION_KEY
private
string
GENERATION_KEY
= '__gen'
Properties
$group
private
string
$group
Methods
__construct()
public
__construct([string $area = 'default' ][, string $groupPrefix = 'middaglib_' ]) : mixed
Parameters
- $area : string = 'default'
-
cache area, appended to the group prefix
- $groupPrefix : string = 'middaglib_'
-
wp_cachegroup prefix; pass the consumer's own to keep its existing group names
clear()
Purge the whole area by bumping its generation; older entries become unreachable behind the new `{generation}:` prefix.
public
clear() : bool
Return values
booldelete()
public
delete(string $key) : bool
Parameters
- $key : string
Return values
booldeleteMultiple()
public
deleteMultiple(iterable<string|int, string> $keys) : bool
Parameters
- $keys : iterable<string|int, string>
Return values
boolget()
public
get(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
- $default : mixed = null
getMultiple()
public
getMultiple(iterable<string|int, string> $keys[, mixed $default = null ]) : iterable<string, mixed>
Parameters
- $keys : iterable<string|int, string>
- $default : mixed = null
Return values
iterable<string, mixed>has()
public
has(string $key) : bool
Parameters
- $key : string
Return values
boolset()
public
set(string $key, mixed $value[, DateInterval|int|null $ttl = null ]) : bool
Parameters
- $key : string
- $value : mixed
- $ttl : DateInterval|int|null = null
Return values
boolsetMultiple()
public
setMultiple(iterable<string, mixed> $values[, DateInterval|int|null $ttl = null ]) : bool
Parameters
- $values : iterable<string, mixed>
- $ttl : DateInterval|int|null = null
Return values
boolgeneration()
Current generation for this area, initialised to 1 on first use.
private
generation() : int
Return values
intscopedKey()
Prefix a caller key with the current area generation.
private
scopedKey(string $key) : string
Parameters
- $key : string
Return values
stringttlSeconds()
Normalise a PSR-16 TTL to whole seconds (0 = no expiration).
private
ttlSeconds(DateInterval|int|null $ttl) : int
Parameters
- $ttl : DateInterval|int|null