1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?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 = [];
- }
- }
|