class StaticFileCacheBackend

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/FileCache/StaticFileCacheBackend.php \Drupal\Tests\Component\FileCache\StaticFileCacheBackend
  2. 10 core/tests/Drupal/Tests/Component/FileCache/StaticFileCacheBackend.php \Drupal\Tests\Component\FileCache\StaticFileCacheBackend
  3. 11.x core/tests/Drupal/Tests/Component/FileCache/StaticFileCacheBackend.php \Drupal\Tests\Component\FileCache\StaticFileCacheBackend

Allows to cache data based on file modification dates in a static cache.

Hierarchy

Expanded class hierarchy of StaticFileCacheBackend

File

core/tests/Drupal/Tests/Component/FileCache/StaticFileCacheBackend.php, line 10

Namespace

Drupal\Tests\Component\FileCache
View source
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 = $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 = [];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
StaticFileCacheBackend::$bin protected property Bin used for storing the data in the static cache.
StaticFileCacheBackend::$cache protected static property Internal static cache.
StaticFileCacheBackend::delete public function Deletes data from a cache backend. Overrides FileCacheBackendInterface::delete
StaticFileCacheBackend::fetch public function Fetches data from the cache backend. Overrides FileCacheBackendInterface::fetch
StaticFileCacheBackend::reset public static function Allows tests to reset the static cache to avoid side effects.
StaticFileCacheBackend::store public function Stores data into a cache backend. Overrides FileCacheBackendInterface::store
StaticFileCacheBackend::__construct public function Constructs a PHP Storage FileCache backend.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.