SlugMapCache
in package
Caches the complete slug maps of the router translators.
Without it, a category translator loads all categories of the module with translations through
the Api manager on the first nameToId() or idToName() (outside the query cache, which stands
at the Api presenter boundary) just to build the two id to slug maps. This class caches
the maps themselves: a hit costs no SQL, hydration or transliteration.
Works like RouteTableCache: envelope {f, v, payload}, tag snapshot before the database
build, store with the old snapshot (a foreign commit plus bump between the snapshot and SETEX
makes the next read a miss, never stale), fail-open (the first PredisException turns the
cache off for the rest of the request), TTL with jitter as the staleness cap for writes outside
a manager (raw SQL, import).
Enabled by the same switch as the route table (cache.config.routerEnabled), independent of
the master enabled of the query cache.
Key app:cache:route:slugmap:{name} is global. IMPORTANT: routing has no user context today;
when it gets one, the key must get it too, otherwise users share maps.
Table of Contents
Constants
- FORMAT_VERSION : mixed = 1
- Payload format version; a mismatch is a miss.
- KEY_SUFFIX : mixed = 'route:slugmap:'
- STATS_SERVICE : mixed = 'SlugMap'
Properties
- $compression : CompressionHelper
- $config : Config
- $redis : ClientInterface
- $redisUnavailable : bool
- Per-request fail-open memo (the first `PredisException` turns the cache off).
- $stats : CacheStats|null
- $tagVersions : TagVersions
Methods
- __construct() : mixed
- clear() : void
- Manual brake: deletes the key of one map (fail-open).
-
load()
: array{idToName: array
>, nameToId: array >} - isMapOfMaps() : bool
- jitteredTtl() : int
- key() : string
-
read()
: array{idToName: array
>, nameToId: array >}|null - Validates and deserializes the payload. Any invalidity is a miss.
- record() : void
- store() : void
Constants
FORMAT_VERSION
Payload format version; a mismatch is a miss.
public
mixed
FORMAT_VERSION
= 1
KEY_SUFFIX
private
mixed
KEY_SUFFIX
= 'route:slugmap:'
STATS_SERVICE
private
mixed
STATS_SERVICE
= 'SlugMap'
Properties
$compression read-only
private
CompressionHelper
$compression
$config read-only
private
Config
$config
$redis read-only
private
ClientInterface
$redis
$redisUnavailable
Per-request fail-open memo (the first `PredisException` turns the cache off).
private
bool
$redisUnavailable
= false
$stats read-only
private
CacheStats|null
$stats
= null
$tagVersions read-only
private
TagVersions
$tagVersions
Methods
__construct()
public
__construct(ClientInterface $redis, Config $config, TagVersions $tagVersions, CompressionHelper $compression[, CacheStats|null $stats = null ]) : mixed
Parameters
- $redis : ClientInterface
- $config : Config
- $tagVersions : TagVersions
- $compression : CompressionHelper
- $stats : CacheStats|null = null
clear()
Manual brake: deletes the key of one map (fail-open).
public
clear(string $name) : void
Parameters
- $name : string
load()
public
load(string $name, array<int, class-string> $tags, callable(): array{idToName: array>, nameToId: array>} $producer) : array{idToName: array>, nameToId: array>}
Parameters
- $name : string
-
stable map name (e.g.
bazaar.category), part of the key - $tags : array<int, class-string>
-
FQCNs of Api entities whose write invalidates the map (
BaseManagerbumps them) -
$producer
: callable(): array{idToName: array
>, nameToId: array >} -
database build of the complete maps; runs only on a miss or when the cache is off
Return values
array{idToName: arrayisMapOfMaps()
private
static isMapOfMaps(mixed $value) : bool
Parameters
- $value : mixed
Return values
booljitteredTtl()
private
jitteredTtl() : int
Return values
intkey()
private
key(string $name) : string
Parameters
- $name : string
Return values
stringread()
Validates and deserializes the payload. Any invalidity is a miss.
private
read(string|null $raw, array<string, int> $snapshot, bool &$invalidated) : array{idToName: array>, nameToId: array>}|null
Parameters
- $raw : string|null
- $snapshot : array<string, int>
-
current tag snapshot
- $invalidated : bool
Return values
array{idToName: arrayrecord()
private
record(array<string, int> $increments) : void
Parameters
- $increments : array<string, int>
store()
private
store(string $key, array<string, int>|null $snapshot, array{idToName: array, nameToId: array} $maps) : void
Parameters
- $key : string
- $snapshot : array<string, int>|null
- $maps : array{idToName: array, nameToId: array}