3 namespace Drupal\Tests\Component\FileCache;
5 use Drupal\Component\FileCache\FileCacheBackendInterface;
8 * Allows to cache data based on file modification dates in a static cache.
10 class StaticFileCacheBackend implements FileCacheBackendInterface {
13 * Internal static cache.
17 protected static $cache = [];
20 * Bin used for storing the data in the static cache.
27 * Constructs a PHP Storage FileCache backend.
29 * @param array $configuration
30 * (optional) Configuration used to configure this object.
32 public function __construct($configuration) {
33 $this->bin = isset($configuration['bin']) ? $configuration['bin'] : 'file_cache';
39 public function fetch(array $cids) {
41 foreach ($cids as $cid) {
42 if (isset(static::$cache[$this->bin][$cid])) {
43 $result[$cid] = static::$cache[$this->bin][$cid];
53 public function store($cid, $data) {
54 static::$cache[$this->bin][$cid] = $data;
60 public function delete($cid) {
61 unset(static::$cache[$this->bin][$cid]);
65 * Allows tests to reset the static cache to avoid side effects.
67 public static function reset() {