class CacheCollectorHelper in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php \Drupal\Tests\Core\Cache\CacheCollectorHelper
Helper class to test the cache collector.
Hierarchy
- class \Drupal\Core\Cache\CacheCollector implements CacheCollectorInterface, DestructableInterface- class \Drupal\Tests\Core\Cache\CacheCollectorHelper
 
Expanded class hierarchy of CacheCollectorHelper
1 file declares its use of CacheCollectorHelper
- CacheCollectorTest.php in core/tests/ Drupal/ KernelTests/ Core/ Cache/ CacheCollectorTest.php 
File
- core/tests/ Drupal/ Tests/ Core/ Cache/ CacheCollectorHelper.php, line 10 
Namespace
Drupal\Tests\Core\CacheView source
class CacheCollectorHelper extends CacheCollector {
  /**
   * Contains data to return on a cache miss.
   * @var array
   */
  protected $cacheMissData = [];
  /**
   * 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| CacheCollector:: | protected | property | The cache backend that should be used. | 1 | 
| CacheCollector:: | protected | property | Stores the cache creation time. | |
| CacheCollector:: | protected | property | Flag that indicates of the cache has been invalidated. | |
| CacheCollector:: | protected | property | Indicates if the collected cache was already loaded. | |
| CacheCollector:: | protected | property | The cache id that is used for the cache entry. | |
| CacheCollector:: | protected | property | An array of keys to add to the cache on service termination. | |
| CacheCollector:: | protected | property | An array of keys to remove from the cache on service termination. | |
| CacheCollector:: | protected | property | The lock backend that should be used. | 1 | 
| CacheCollector:: | protected | property | Storage for the data itself. | |
| CacheCollector:: | protected | property | A list of tags that are used for the cache entry. | |
| CacheCollector:: | public | function | Clears the collected cache entry. Overrides CacheCollectorInterface:: | 1 | 
| CacheCollector:: | public | function | Deletes the element. Overrides CacheCollectorInterface:: | |
| CacheCollector:: | public | function | Performs destruct operations. Overrides DestructableInterface:: | |
| CacheCollector:: | public | function | Gets value from the cache. Overrides CacheCollectorInterface:: | 2 | 
| CacheCollector:: | protected | function | Gets the cache ID. | 3 | 
| CacheCollector:: | public | function | Returns whether data exists for this key. Overrides CacheCollectorInterface:: | 1 | 
| CacheCollector:: | protected | function | Invalidate the cache. | |
| CacheCollector:: | protected | function | Loads the cache if not already done. | 1 | 
| CacheCollector:: | protected | function | Normalizes a cache ID in order to comply with database limitations. | |
| CacheCollector:: | protected | function | Flags an offset value to be written to the persistent cache. | |
| CacheCollector:: | public | function | Resets the local cache. Overrides CacheCollectorInterface:: | 1 | 
| CacheCollector:: | protected | function | Writes a value to the persistent cache immediately. | 1 | 
| CacheCollector:: | public | function | Constructs a CacheCollector object. | 6 | 
| CacheCollectorHelper:: | protected | property | Contains data to return on a cache miss. | |
| CacheCollectorHelper:: | protected | property | Number of calls to \Drupal\Core\Cache\CacheCollector::resolveCacheMiss(). | |
| CacheCollectorHelper:: | public | function | Returns the number of cache misses. | |
| CacheCollectorHelper:: | public | function | Resolves a cache miss. Overrides CacheCollector:: | |
| CacheCollectorHelper:: | public | function | Implements \Drupal\Core\Cache\CacheCollectorInterface::set(). Overrides CacheCollector:: | |
| CacheCollectorHelper:: | public | function | Sets data to return from a cache miss resolve. | 
