You are here

class CacheCollectorHelper in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php \Drupal\Tests\Core\Cache\CacheCollectorHelper

Helper class to test the cache collector.

Hierarchy

Expanded class hierarchy of CacheCollectorHelper

1 file declares its use of CacheCollectorHelper
CacheCollectorTest.php in core/tests/Drupal/KernelTests/Core/Cache/CacheCollectorTest.php
\Drupal\KernelTests\Core\Cache\CacheCollectorTest.

File

core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php, line 15
Contains \Drupal\Tests\Core\Cache\CacheCollectorHelper.

Namespace

Drupal\Tests\Core\Cache
View source
class CacheCollectorHelper extends CacheCollector {

  /**
   * Contains data to return on a cache miss.
   * @var array
   */
  protected $cacheMissData = array();

  /**
   * Number of calls to \Drupal\Core\Cache\CacheCollector::resolveCacheMiss().
   *
   * @var int
   */
  protected $cacheMisses = 0;

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    parent::set($key, $value);
    $this
      ->persist($key);
  }

  /**
   * {@inheritdoc}
   */
  public function resolveCacheMiss($key) {
    $this->cacheMisses++;
    if (isset($this->cacheMissData[$key])) {
      $this->storage[$key] = $this->cacheMissData[$key];
      $this
        ->persist($key);
      return $this->cacheMissData[$key];
    }
  }

  /**
   * Sets data to return from a cache miss resolve.
   *
   * @param string $key
   *   The key being looked for.
   * @param mixed $value
   *   The value to return.
   */
  public function setCacheMissData($key, $value) {
    $this->cacheMissData[$key] = $value;
  }

  /**
   * Returns the number of cache misses.
   *
   * @return int
   *   Number of calls to the resolve cache miss method.
   */
  public function getCacheMisses() {
    return $this->cacheMisses;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheCollector::$cache protected property The cache backend that should be used. 2
CacheCollector::$cacheCreated protected property Stores the cache creation time.
CacheCollector::$cacheInvalidated protected property Flag that indicates of the cache has been invalidated.
CacheCollector::$cacheLoaded protected property Indicates if the collected cache was already loaded.
CacheCollector::$cid protected property The cache id that is used for the cache entry.
CacheCollector::$keysToPersist protected property An array of keys to add to the cache on service termination.
CacheCollector::$keysToRemove protected property An array of keys to remove from the cache on service termination.
CacheCollector::$lock protected property The lock backend that should be used. 2
CacheCollector::$storage protected property Storage for the data itself.
CacheCollector::$tags protected property A list of tags that are used for the cache entry.
CacheCollector::clear public function Clears the collected cache entry. Overrides CacheCollectorInterface::clear 1
CacheCollector::delete public function Deletes the element. Overrides CacheCollectorInterface::delete
CacheCollector::destruct public function Performs destruct operations. Overrides DestructableInterface::destruct
CacheCollector::get public function Gets value from the cache. Overrides CacheCollectorInterface::get 2
CacheCollector::getCid protected function Gets the cache ID. 3
CacheCollector::has public function Returns whether data exists for this key. Overrides CacheCollectorInterface::has 1
CacheCollector::invalidateCache protected function Invalidate the cache.
CacheCollector::lazyLoadCache protected function Loads the cache if not already done. 1
CacheCollector::normalizeLockName protected function Normalizes a cache ID in order to comply with database limitations.
CacheCollector::persist protected function Flags an offset value to be written to the persistent cache.
CacheCollector::reset public function Resets the local cache. Overrides CacheCollectorInterface::reset 1
CacheCollector::updateCache protected function Writes a value to the persistent cache immediately. 1
CacheCollector::__construct public function Constructs a CacheCollector object. 5
CacheCollectorHelper::$cacheMissData protected property Contains data to return on a cache miss.
CacheCollectorHelper::$cacheMisses protected property Number of calls to \Drupal\Core\Cache\CacheCollector::resolveCacheMiss().
CacheCollectorHelper::getCacheMisses public function Returns the number of cache misses.
CacheCollectorHelper::resolveCacheMiss public function Resolves a cache miss. Overrides CacheCollector::resolveCacheMiss
CacheCollectorHelper::set public function Implements \Drupal\Core\Cache\CacheCollectorInterface::set(). Overrides CacheCollector::set
CacheCollectorHelper::setCacheMissData public function Sets data to return from a cache miss resolve.