StoredValueCache
class StoredValueCache
Shares a database store's stored values between servers through a cache store.
Each cached value records the partition and scope tokens that were current when it was read. Writes replace those tokens instead of deleting values, so a value read before a write but cached after it no longer matches and is ignored. The database stays authoritative, and an evicted value is read again rather than resolved again.
Constants
| DEFAULT_TTL |
The default number of seconds values and tokens are cached for. |
Methods
Create a new stored value cache instance.
Determine if values are read from and published to the cache.
Read the cached values of the given features and scopes.
Publish the stored JSON values of the given features and scopes under the tokens they were read with.
Invalidate the cached values of the given scopes.
Invalidate every cached value in the partition.
Replace the given tokens in every target cache.
Get the identity of the rows read through the given connection and partition.
Get the key of the partition token.
Get the key of a scope's token.
Get the key of a feature's cached value for a scope.
Get the fixed-length cache key of an entry.
Encode a key segment so adjacent segments can't run together.
Details
at line 36
__construct(string $table, array $targets, Repository|null $cache = null, int $ttl = self::DEFAULT_TTL)
Create a new stored value cache instance.
at line 47
bool
storesValues()
Determine if values are read from and published to the cache.
at line 61
array
read(string $connection, FeaturePartition|null $partition, array $pairs)
Read the cached values of the given features and scopes.
Missing tokens are created before the database is read, so a write that commits afterwards replaces them. Without tokens, nothing read now may be published.
at line 120
void
publish(string $connection, FeaturePartition|null $partition, array $tokens, array $stored)
Publish the stored JSON values of the given features and scopes under the tokens they were read with.
at line 139
void
rotateScopes(string $connection, FeaturePartition|null $partition, array $scopes)
Invalidate the cached values of the given scopes.
at line 154
void
rotatePartition(string $connection, FeaturePartition|null $partition)
Invalidate every cached value in the partition.
at line 168
protected void
rotate(array $tokens)
Replace the given tokens in every target cache.
Every target is attempted, since a failure in one doesn't make the others stale.
at line 196
protected string
storage(string $connection, FeaturePartition|null $partition)
Get the identity of the rows read through the given connection and partition.
Stores reading the same rows share entries, so the identity names the storage, not the store.
at line 206
protected string
partitionTokenKey(string $storage)
Get the key of the partition token.
at line 214
protected string
scopeTokenKey(string $storage, int|string $scope)
Get the key of a scope's token.
at line 222
protected string
valueKey(string $storage, int|string $feature, int|string $scope)
Get the key of a feature's cached value for a scope.
at line 233
protected string
key(string $kind, string $identity)
Get the fixed-length cache key of an entry.
Scopes and feature names can be longer than some cache stores allow in a key. SHA-256 keeps one scope from being crafted to share another scope's key.
at line 241
protected string
segment(int|string $value)
Encode a key segment so adjacent segments can't run together.