Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Cache / CacheCollectorHelper.php
1 <?php
2
3 namespace Drupal\Tests\Core\Cache;
4
5 use Drupal\Core\Cache\CacheCollector;
6
7 /**
8  * Helper class to test the cache collector.
9  */
10 class CacheCollectorHelper extends CacheCollector {
11
12   /**
13    * Contains data to return on a cache miss.
14    * @var array
15    */
16   protected $cacheMissData = [];
17
18   /**
19    * Number of calls to \Drupal\Core\Cache\CacheCollector::resolveCacheMiss().
20    *
21    * @var int
22    */
23   protected $cacheMisses = 0;
24
25   /**
26    * {@inheritdoc}
27    */
28   public function set($key, $value) {
29     parent::set($key, $value);
30     $this->persist($key);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function resolveCacheMiss($key) {
37     $this->cacheMisses++;
38     if (isset($this->cacheMissData[$key])) {
39       $this->storage[$key] = $this->cacheMissData[$key];
40       $this->persist($key);
41       return $this->cacheMissData[$key];
42     }
43   }
44
45   /**
46    * Sets data to return from a cache miss resolve.
47    *
48    * @param string $key
49    *   The key being looked for.
50    * @param mixed $value
51    *   The value to return.
52    */
53   public function setCacheMissData($key, $value) {
54     $this->cacheMissData[$key] = $value;
55   }
56
57   /**
58    * Returns the number of cache misses.
59    *
60    * @return int
61    *   Number of calls to the resolve cache miss method.
62    */
63   public function getCacheMisses() {
64     return $this->cacheMisses;
65   }
66
67 }