BackendChain example

use Drupal\Core\Cache\BackendChain;
use Drupal\Core\Cache\MemoryBackend;

/** * Unit test of the backend chain using the generic cache unit test base. * * @group Cache */
class BackendChainTest extends GenericCacheBackendUnitTestBase {

  protected function createCacheBackend($bin) {
    $chain = new BackendChain();

    // We need to create some various backends in the chain.     $chain
      ->appendBackend(new MemoryBackend())
      ->prependBackend(new MemoryBackend())
      ->appendBackend(new MemoryBackend());

    \Drupal::service('cache_tags.invalidator')->addInvalidator($chain);

    return $chain;
  }

}
$this->thirdBackend->set('t123', 1233);

    // Set a key present on the second and the third (for get), those two will     // be different, this will ensure from where we get the key.     $this->secondBackend->set('t23', 232);
    $this->thirdBackend->set('t23', 233);

    // Set a key on only the third, we will ensure propagation using this one.     $this->thirdBackend->set('t3', 33);

    // Create the chain.     $this->chain = new BackendChain();
    $this->chain
      ->appendBackend($this->firstBackend)
      ->appendBackend($this->secondBackend)
      ->appendBackend($this->thirdBackend);
  }

  /** * Tests the get feature. */
  public function testGet() {
    $cached = $this->chain->get('t123');
    
Home | Imprint | This part of the site doesn't use cookies.