You are here

class StaticFileCacheBackend in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 15
Contains \Drupal\Tests\Component\FileCache\StaticFileCacheBackend.

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

}

Members

Namesort descending Modifiers Type Description Overrides
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.