TagVersions
in package
Tag versions per entity class.
Storage: {keyPrefix}cache:tag:{EntityFQCN} is an integer, INCR invalidates, no TTL (dozens of keys).
A read snapshots the current tag versions with MGET before the database query. IMPORTANT:
keep this order; a foreign commit plus bump between the snapshot and storing the payload
then leaves the payload with an old snapshot, so the next read is a miss instead of a stale hit.
A missing tag is bootstrapped with SET NX 1, otherwise a class that nobody ever bumped
would stay in a permanent miss loop.
Fail-open is the caller's job (QueryCache catches Redis exceptions, CacheTagInvalidator wraps the bump). This class does not swallow exceptions so the caller sees them.
Table of Contents
Properties
Methods
- __construct() : mixed
- bump() : void
- Invalidates by incrementing the tag of every class (monotonic, so resurrection after a delete is impossible).
- current() : array<string, int>
- Returns the current versions of the tags of the given classes. The order is deterministic (keys sorted) so the snapshot is comparable with the stored `v`.
-
currentWithCompanion()
: array{snapshot: array
, companion: ?string} - Returns the tag version snapshot plus the value of a companion key in one round-trip (pipeline `MGET` + `GET`).
- normalizeClasses() : array<int, string>
- tagKey() : string
Properties
$config read-only
private
Config
$config
$redis read-only
private
Client
$redis
Methods
__construct()
public
__construct(Client $redis, Config $config) : mixed
Parameters
- $redis : Client
- $config : Config
bump()
Invalidates by incrementing the tag of every class (monotonic, so resurrection after a delete is impossible).
public
bump(array<string|int, string> $classes) : void
Parameters
- $classes : array<string|int, string>
current()
Returns the current versions of the tags of the given classes. The order is deterministic (keys sorted) so the snapshot is comparable with the stored `v`.
public
current(array<string|int, string> $classes) : array<string, int>
Parameters
- $classes : array<string|int, string>
Return values
array<string, int> —class to version, sorted by class
currentWithCompanion()
Returns the tag version snapshot plus the value of a companion key in one round-trip (pipeline `MGET` + `GET`).
public
currentWithCompanion(array<string|int, string> $classes, string $companionKey) : array{snapshot: array, companion: ?string}
Hot path of the route table cache (RouteTableCache): the table is
a single key with no dependency between commands. As in current(), the snapshot is
taken before the database build. Bootstrapping missing tags (SETNX) runs outside the
pipeline and only on a cold start; the companion still comes from the pipeline.
Parameters
- $classes : array<string|int, string>
- $companionKey : string
-
key read with
GETin the same pipeline
Return values
array{snapshot: arraynormalizeClasses()
private
normalizeClasses(array<string|int, string> $classes) : array<int, string>
Parameters
- $classes : array<string|int, string>
Return values
array<int, string> —unique and sorted (deterministic snapshot)
tagKey()
private
tagKey(string $class) : string
Parameters
- $class : string