class RedisCacheTagsChecksum in Redis 8
Cache tags invalidations checksum implementation that uses redis.
Hierarchy
- class \Drupal\redis\Cache\RedisCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTagsInvalidatorInterface uses CacheTagsChecksumTrait, RedisPrefixTrait
Expanded class hierarchy of RedisCacheTagsChecksum
1 string reference to 'RedisCacheTagsChecksum'
1 service uses RedisCacheTagsChecksum
File
- src/
Cache/ RedisCacheTagsChecksum.php, line 14
Namespace
Drupal\redis\CacheView source
class RedisCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTagsInvalidatorInterface {
use RedisPrefixTrait;
use CacheTagsChecksumTrait;
/**
* Contains already loaded cache invalidations from the database.
*
* @var array
*/
protected $tagCache = [];
/**
* A list of tags that have already been invalidated in this request.
*
* Used to prevent the invalidation of the same cache tag multiple times.
*
* @var array
*/
protected $invalidatedTags = [];
/**
* {@inheritdoc}
*/
protected $client;
/**
* @var string
*/
protected $clientType;
/**
* Creates a PHpRedis cache backend.
*/
public function __construct(ClientFactory $factory) {
$this->client = $factory
->getClient();
$this->clientType = $factory
->getClientName();
}
/**
* {@inheritdoc}
*/
public function doInvalidateTags(array $tags) {
$keys = array_map([
$this,
'getTagKey',
], $tags);
// We want to differentiate between PhpRedis and Redis clients.
if ($this->clientType === 'PhpRedis') {
$multi = $this->client
->multi();
foreach ($keys as $key) {
$multi
->incr($key);
}
$multi
->exec();
}
elseif ($this->clientType === 'Predis') {
$pipe = $this->client
->pipeline();
foreach ($keys as $key) {
$pipe
->incr($key);
}
$pipe
->execute();
}
}
/**
* {@inheritdoc}
*/
protected function getTagInvalidationCounts(array $tags) {
$keys = array_map([
$this,
'getTagKey',
], $tags);
// The mget command returns the values as an array with numeric keys,
// combine it with the tags array to get the expected return value and run
// it through intval() to convert to integers and FALSE to 0.
$values = $this->client
->mget($keys);
return $values ? array_map('intval', array_combine($tags, $values)) : [];
}
/**
* Return the key for the given cache tag.
*
* @param string $tag
* The cache tag.
*
* @return string
* The prefixed cache tag.
*/
protected function getTagKey($tag) {
return $this
->getPrefix() . ':cachetags:' . $tag;
}
/**
* {@inheritdoc}
*/
protected function getDatabaseConnection() {
// This is not injected to avoid a dependency on the database in the
// critical path. It is only needed during cache tag invalidations.
return \Drupal::database();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheTagsChecksumInterface:: |
constant | The invalid checksum returned if a database transaction is in progress. | ||
CacheTagsChecksumTrait:: |
protected | property | The set of cache tags whose invalidation is delayed. | |
CacheTagsChecksumTrait:: |
protected | function | Calculates the current checksum for a given set of tags. | |
CacheTagsChecksumTrait:: |
public | function | Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::getCurrentChecksum() | |
CacheTagsChecksumTrait:: |
public | function | Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::invalidateTags() | |
CacheTagsChecksumTrait:: |
public | function | Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::isValid() | |
CacheTagsChecksumTrait:: |
public | function | Implements \Drupal\Core\Cache\CacheTagsChecksumInterface::reset() | |
CacheTagsChecksumTrait:: |
public | function | Callback to be invoked just after a database transaction gets committed. | |
RedisCacheTagsChecksum:: |
protected | property | ||
RedisCacheTagsChecksum:: |
protected | property | ||
RedisCacheTagsChecksum:: |
protected | property |
A list of tags that have already been invalidated in this request. Overrides CacheTagsChecksumTrait:: |
|
RedisCacheTagsChecksum:: |
protected | property |
Contains already loaded cache invalidations from the database. Overrides CacheTagsChecksumTrait:: |
|
RedisCacheTagsChecksum:: |
public | function |
Marks cache items with any of the specified tags as invalid. Overrides CacheTagsChecksumTrait:: |
|
RedisCacheTagsChecksum:: |
protected | function |
Returns the database connection. Overrides CacheTagsChecksumTrait:: |
|
RedisCacheTagsChecksum:: |
protected | function |
Fetches invalidation counts for cache tags. Overrides CacheTagsChecksumTrait:: |
|
RedisCacheTagsChecksum:: |
protected | function | Return the key for the given cache tag. | |
RedisCacheTagsChecksum:: |
public | function | Creates a PHpRedis cache backend. | |
RedisPrefixTrait:: |
protected | property | ||
RedisPrefixTrait:: |
protected | function | Get global default prefix | |
RedisPrefixTrait:: |
protected | function | Get prefix | |
RedisPrefixTrait:: |
public | function | Set prefix |