RedisTagAwareAdapter
extends AbstractTagAwareAdapter
in package
Uses
RedisTrait
Stores tag id <> cache id relationship as a Redis Set, lookup on invalidation using RENAME+SMEMBERS.
Set (tag relation info) is stored without expiry (non-volatile), while cache always gets an expiry (volatile) even if not set by caller. Thus if you configure redis with the right eviction policy you can be safe this tag <> cache relationship survives eviction (cache cleanup when Redis runs out of memory).
Requirements:
- Client: PHP Redis or Predis Note: Due to lack of RENAME support it is NOT recommended to use Cluster on Predis, instead use phpredis.
- Server: Redis 2.8+
Configured with any
volatile-*
eviction policy, ORnoeviction
if it will NEVER fill up memory
Design limitations:
- Max 4 billion cache keys per cache tag as limited by Redis Set datatype. E.g. If you use a "all" items tag for expiry instead of clear(), that limits you to 4 billion cache items also.
Tags
Table of Contents
- BULK_DELETE_LIMIT = 10000
- Limits for how many keys are deleted in batch.
- DEFAULT_CACHE_TTL = 8640000
- On cache items without a lifetime set, we set it to 100 days. This is to make sure cache items are preferred to be evicted over tag Sets, if eviction policy is configured according to requirements.
- $redisEvictionPolicy : string|null
- __construct() : mixed
- doDeleteTagRelations() : bool
- {@inheritdoc}
- doDeleteYieldTags() : iteratable<string|int, mixed>
- {@inheritdoc}
- doInvalidate() : bool
- {@inheritdoc}
- doSave() : array<string|int, mixed>
- {@inheritdoc}
- getRedisEvictionPolicy() : string
- renameKeys() : array<string|int, mixed>
- Renames several keys in order to be able to operate on them without risk of race conditions.
Constants
BULK_DELETE_LIMIT
Limits for how many keys are deleted in batch.
private
mixed
BULK_DELETE_LIMIT
= 10000
DEFAULT_CACHE_TTL
On cache items without a lifetime set, we set it to 100 days. This is to make sure cache items are preferred to be evicted over tag Sets, if eviction policy is configured according to requirements.
private
mixed
DEFAULT_CACHE_TTL
= 8640000
Properties
$redisEvictionPolicy
private
string|null
$redisEvictionPolicy
detected eviction policy used on Redis server
Methods
__construct()
public
__construct(Redis|RedisArray|RedisCluster|ClientInterface $redisClient[, string $namespace = '' ], int $defaultLifetime[, MarshallerInterface $marshaller = null ]) : mixed
Parameters
- $redisClient : Redis|RedisArray|RedisCluster|ClientInterface
-
The redis client
- $namespace : string = ''
-
The default namespace
- $defaultLifetime : int
-
The default lifetime
- $marshaller : MarshallerInterface = null
Return values
mixed —doDeleteTagRelations()
{@inheritdoc}
protected
doDeleteTagRelations(array<string|int, mixed> $tagData) : bool
Parameters
- $tagData : array<string|int, mixed>
Return values
bool —doDeleteYieldTags()
{@inheritdoc}
protected
doDeleteYieldTags(array<string|int, mixed> $ids) : iteratable<string|int, mixed>
Parameters
- $ids : array<string|int, mixed>
Return values
iteratable<string|int, mixed> —doInvalidate()
{@inheritdoc}
protected
doInvalidate(array<string|int, mixed> $tagIds) : bool
Parameters
- $tagIds : array<string|int, mixed>
Return values
bool —doSave()
{@inheritdoc}
protected
doSave(array<string|int, mixed> $values, int $lifetime[, array<string|int, mixed> $addTagData = [] ][, array<string|int, mixed> $delTagData = [] ]) : array<string|int, mixed>
Parameters
- $values : array<string|int, mixed>
- $lifetime : int
- $addTagData : array<string|int, mixed> = []
- $delTagData : array<string|int, mixed> = []
Return values
array<string|int, mixed> —getRedisEvictionPolicy()
private
getRedisEvictionPolicy() : string
Return values
string —renameKeys()
Renames several keys in order to be able to operate on them without risk of race conditions.
private
renameKeys(mixed $redis, array<string|int, mixed> $ids) : array<string|int, mixed>
Filters out keys that do not exist before returning new keys.
Parameters
- $redis : mixed
- $ids : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Filtered list of the valid moved keys (only those that existed)