Mercurial > hg > isophonics-drupal-site
view core/tests/Drupal/Tests/Component/FileCache/StaticFileCacheBackend.php @ 3:e11175134f4e
Attempt to introduce editable version of theme
author | Chris Cannam |
---|---|
date | Tue, 05 Dec 2017 11:25:38 +0000 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line source
<?php namespace Drupal\Tests\Component\FileCache; use Drupal\Component\FileCache\FileCacheBackendInterface; /** * Allows to cache data based on file modification dates in a static cache. */ class StaticFileCacheBackend implements FileCacheBackendInterface { /** * Internal static cache. * * @var array */ protected static $cache = []; /** * Bin used for storing the data in the static cache. * * @var string */ protected $bin; /** * Constructs a PHP Storage FileCache backend. * * @param array $configuration * (optional) Configuration used to configure this object. */ public function __construct($configuration) { $this->bin = isset($configuration['bin']) ? $configuration['bin'] : 'file_cache'; } /** * {@inheritdoc} */ public function fetch(array $cids) { $result = []; foreach ($cids as $cid) { if (isset(static::$cache[$this->bin][$cid])) { $result[$cid] = static::$cache[$this->bin][$cid]; } } return $result; } /** * {@inheritdoc} */ public function store($cid, $data) { static::$cache[$this->bin][$cid] = $data; } /** * {@inheritdoc} */ public function delete($cid) { unset(static::$cache[$this->bin][$cid]); } /** * Allows tests to reset the static cache to avoid side effects. */ public static function reset() { static::$cache = []; } }