class CacheTagsChecksumDecorator
Same name in other branches
- 11.x core/modules/system/tests/modules/performance_test/src/Cache/CacheTagsChecksumDecorator.php \Drupal\performance_test\Cache\CacheTagsChecksumDecorator
Wraps an existing cache tags checksum invalidator to track calls separately.
Hierarchy
- class \Drupal\performance_test\Cache\CacheTagsChecksumDecorator implements \Drupal\Core\Cache\CacheTagsChecksumInterface, \Drupal\Core\Cache\CacheTagsInvalidatorInterface
Expanded class hierarchy of CacheTagsChecksumDecorator
1 string reference to 'CacheTagsChecksumDecorator'
- performance_test.services.yml in core/
modules/ system/ tests/ modules/ performance_test/ performance_test.services.yml - core/modules/system/tests/modules/performance_test/performance_test.services.yml
1 service uses CacheTagsChecksumDecorator
- performance_test.cache_tags.invalidator.checksum in core/
modules/ system/ tests/ modules/ performance_test/ performance_test.services.yml - Drupal\performance_test\Cache\CacheTagsChecksumDecorator
File
-
core/
modules/ system/ tests/ modules/ performance_test/ src/ Cache/ CacheTagsChecksumDecorator.php, line 14
Namespace
Drupal\performance_test\CacheView source
class CacheTagsChecksumDecorator implements CacheTagsChecksumInterface, CacheTagsInvalidatorInterface {
public function __construct(CacheTagsChecksumInterface $checksumInvalidator, PerformanceDataCollector $performanceDataCollector) {
}
/**
* {@inheritdoc}
*/
public function getCurrentChecksum(array $tags) {
// If there are no cache tags, there is no checksum to get and the decorated
// method will be a no-op, so don't log anything.
if (empty($tags)) {
return $this->checksumInvalidator
->getCurrentChecksum($tags);
}
$start = microtime(TRUE);
$return = $this->checksumInvalidator
->getCurrentChecksum($tags);
$stop = microtime(TRUE);
$this->logCacheTagOperation($tags, $start, $stop, CacheTagOperation::GetCurrentChecksum);
return $return;
}
/**
* {@inheritdoc}
*/
public function isValid($checksum, array $tags) {
// If there are no cache tags, the cache item is always valid, and the child
// method will be a no-op, so don't log anything.
if (empty($tags)) {
return $this->checksumInvalidator
->isValid($checksum, $tags);
}
$start = microtime(TRUE);
$return = $this->checksumInvalidator
->isValid($checksum, $tags);
$stop = microtime(TRUE);
$this->logCacheTagOperation($tags, $start, $stop, CacheTagOperation::IsValid);
return $return;
}
/**
* {@inheritdoc}
*/
public function invalidateTags(array $tags) {
// If there are no cache tags, there is nothing to invalidate, and the
// decorated method will be a no-op, so don't log anything.
if (empty($tags)) {
return $this->checksumInvalidator
->invalidateTags($tags);
}
$start = microtime(TRUE);
$return = $this->checksumInvalidator
->invalidateTags($tags);
$stop = microtime(TRUE);
$this->logCacheTagOperation($tags, $start, $stop, CacheTagOperation::InvalidateTags);
return $return;
}
/**
* {@inheritdoc}
*/
public function reset() {
$this->checksumInvalidator
->reset();
}
/**
* Logs a cache tag operation.
*
* @param string[] $tags
* The cache tags.
* @param float $start
* The start microtime.
* @param float $stop
* The stop microtime.
* @param \Drupal\performance_test\Cache\CacheTagOperation $operation
* The type of operation being logged.
*
* @return void
*/
protected function logCacheTagOperation(array $tags, float $start, float $stop, CacheTagOperation $operation) : void {
$this->performanceDataCollector
->addCacheTagOperation([
'operation' => $operation,
'tags' => implode(', ', $tags),
'start' => $start,
'stop' => $stop,
]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
CacheTagsChecksumDecorator::getCurrentChecksum | public | function | |
CacheTagsChecksumDecorator::invalidateTags | public | function | |
CacheTagsChecksumDecorator::isValid | public | function | |
CacheTagsChecksumDecorator::logCacheTagOperation | protected | function | Logs a cache tag operation. |
CacheTagsChecksumDecorator::reset | public | function | |
CacheTagsChecksumDecorator::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.