appendBackend example


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;
  }

}
// 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');
    $this->assertNotFalse($cached, 'Got key that is on all backends');
    $this->assertSame(1231, $cached->data, 'Got the key from the backend 1');

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