class CacheTagsChecksumDecorator

Wraps an existing cache tags checksum invalidator to track calls separately.

Hierarchy

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\Cache
View source
class CacheTagsChecksumDecorator implements CacheTagsChecksumInterface, CacheTagsInvalidatorInterface {
  public function __construct(protected readonly CacheTagsChecksumInterface $checksumInvalidator, protected readonly 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 Overriden Title
CacheTagsChecksumDecorator::getCurrentChecksum public function Returns the sum total of validations for a given set of tags. Overrides CacheTagsChecksumInterface::getCurrentChecksum
CacheTagsChecksumDecorator::invalidateTags public function Marks cache items with any of the specified tags as invalid. Overrides CacheTagsInvalidatorInterface::invalidateTags
CacheTagsChecksumDecorator::isValid public function Returns whether the checksum is valid for the given cache tags. Overrides CacheTagsChecksumInterface::isValid
CacheTagsChecksumDecorator::logCacheTagOperation protected function Logs a cache tag operation.
CacheTagsChecksumDecorator::reset public function Reset statically cached tags. Overrides CacheTagsChecksumInterface::reset
CacheTagsChecksumDecorator::__construct public function
CacheTagsChecksumInterface::INVALID_CHECKSUM_WHILE_IN_TRANSACTION constant The invalid checksum returned if a database transaction is in progress.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.