PhpBackend example


class PhpBackendTest extends GenericCacheBackendUnitTestBase {

  /** * Creates a new instance of MemoryBackend. * * @return \Drupal\Core\Cache\CacheBackendInterface * A new PhpBackend object. */
  protected function createCacheBackend($bin) {
    $backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'));
    return $backend;
  }

}
/** * Gets PhpBackend for the specified cache bin. * * @param $bin * The cache bin for which the object is created. * * @return \Drupal\Core\Cache\PhpBackend * The cache backend object for the specified cache bin. */
  public function get($bin) {
    return new PhpBackend($bin$this->checksumProvider);
  }

}

class ChainedFastBackendTest extends GenericCacheBackendUnitTestBase {

  /** * Creates a new instance of ChainedFastBackend. * * @return \Drupal\Core\Cache\ChainedFastBackend * A new ChainedFastBackend object. */
  protected function createCacheBackend($bin) {
    $consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum')$bin, 100);
    $fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'));
    $backend = new ChainedFastBackend($consistent_backend$fast_backend$bin);
    // Explicitly register the cache bin as it can not work through the     // cache bin list in the container.     \Drupal::service('cache_tags.invalidator')->addInvalidator($backend);
    return $backend;
  }

}
Home | Imprint | This part of the site doesn't use cookies.