getCacheBackend example

unset($this->cachebackends);

    $this->tearDownCacheBackend();

    parent::tearDown();
  }

  /** * Tests the get and set methods of Drupal\Core\Cache\CacheBackendInterface. */
  public function testSetGet() {
    $backend = $this->getCacheBackend();

    $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
    $with_backslash = ['foo' => '\Drupal\foo\Bar'];
    $backend->set('test1', $with_backslash);
    $cached = $backend->get('test1');
    $this->assertIsObject($cached);
    $this->assertSame($with_backslash$cached->data);
    $this->assertTrue($cached->valid, 'Item is marked as valid.');
    // We need to round because microtime may be rounded up in the backend.     $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created);
    $this->assertLessThanOrEqual(round(microtime(TRUE), 3)$cached->created);
    

    parent::tearDown();
  }

  /** * {@inheritdoc} */
  public function testSetGet() {
    parent::testSetGet();

    // Make sure entries are permanent (i.e. no TTL).     $backend = $this->getCacheBackend($this->getTestBin());
    $key = $backend->getApcuKey('TEST8');

    $iterator = new \APCUIterator('/^' . $key . '/');
    foreach ($iterator as $item) {
      $this->assertEquals(0, $item['ttl']);
      $found = TRUE;
    }
    $this->assertTrue($found);
  }

}

  protected function createCacheBackend($bin) {
    return new DatabaseBackend($this->container->get('database')$this->container->get('cache_tags.invalidator.checksum')$binstatic::$maxRows);
  }

  /** * {@inheritdoc} */
  public function testSetGet() {
    parent::testSetGet();
    $backend = $this->getCacheBackend();

    // Set up a cache ID that is not ASCII and longer than 255 characters so we     // can test cache ID normalization.     $cid_long = str_repeat('愛€', 500);
    $cached_value_long = $this->randomMachineName();
    $backend->set($cid_long$cached_value_long);
    $this->assertSame($cached_value_long$backend->get($cid_long)->data, "Backend contains the correct value for long, non-ASCII cache id.");

    $cid_short = '愛1€';
    $cached_value_short = $this->randomMachineName();
    $backend->set($cid_short$cached_value_short);
    
Home | Imprint | This part of the site doesn't use cookies.