Commit 106e3d42 authored by alexpott's avatar alexpott

Issue #2386161 by Berdir, Wim Leers, beejeebus, olli: ChainedFastBackend...

Issue #2386161 by Berdir, Wim Leers, beejeebus, olli: ChainedFastBackend doesn't set 'expires' and 'tags' when writing to fastBackend
parent 20a8ccfd
......@@ -160,7 +160,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
if ($cids) {
foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) {
$cache[$item->cid] = $item;
$this->fastBackend->set($item->cid, $item->data);
$this->fastBackend->set($item->cid, $item->data, $item->expire, $item->tags);
}
}
......@@ -171,8 +171,8 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
* {@inheritdoc}
*/
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
$this->markAsOutdated();
$this->consistentBackend->set($cid, $data, $expire, $tags);
$this->markAsOutdated();
$this->fastBackend->set($cid, $data, $expire, $tags);
}
......@@ -180,8 +180,8 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array
* {@inheritdoc}
*/
public function setMultiple(array $items) {
$this->markAsOutdated();
$this->consistentBackend->setMultiple($items);
$this->markAsOutdated();
$this->fastBackend->setMultiple($items);
}
......@@ -189,16 +189,16 @@ public function setMultiple(array $items) {
* {@inheritdoc}
*/
public function delete($cid) {
$this->markAsOutdated();
$this->consistentBackend->deleteMultiple(array($cid));
$this->markAsOutdated();
}
/**
* {@inheritdoc}
*/
public function deleteMultiple(array $cids) {
$this->markAsOutdated();
$this->consistentBackend->deleteMultiple($cids);
$this->markAsOutdated();
}
/**
......@@ -213,8 +213,8 @@ public function deleteTags(array $tags) {
* {@inheritdoc}
*/
public function deleteAll() {
$this->markAsOutdated();
$this->consistentBackend->deleteAll();
$this->markAsOutdated();
}
/**
......@@ -228,24 +228,24 @@ public function invalidate($cid) {
* {@inheritdoc}
*/
public function invalidateMultiple(array $cids) {
$this->markAsOutdated();
$this->consistentBackend->invalidateMultiple($cids);
$this->markAsOutdated();
}
/**
* {@inheritdoc}
*/
public function invalidateTags(array $tags) {
$this->markAsOutdated();
$this->consistentBackend->invalidateTags($tags);
$this->markAsOutdated();
}
/**
* {@inheritdoc}
*/
public function invalidateAll() {
$this->markAsOutdated();
$this->consistentBackend->invalidateAll();
$this->markAsOutdated();
}
/**
......@@ -289,7 +289,11 @@ protected function markAsOutdated() {
// Clocks on a single server can drift. Multiple servers may have slightly
// differing opinions about the current time. Given that, do not assume
// 'now' on this server is always later than our stored timestamp.
$now = microtime(TRUE);
// Also add 1 millisecond, to ensure that caches written earlier in the same
// millisecond are invalidated. It is possible that caches will be later in
// the same millisecond and are then incorrectly invalidated, but that only
// costs one additional roundtrip to the persistent cache.
$now = round(microtime(TRUE) + .001, 3);
if ($now > $this->getLastWriteTimestamp()) {
$this->lastWriteTimestamp = $now;
$this->consistentBackend->set(self::LAST_WRITE_TIMESTAMP_PREFIX . $this->bin, $this->lastWriteTimestamp);
......
......@@ -28,4 +28,5 @@ protected function createCacheBackend($bin) {
return $chain;
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Cache\ChainedFastBackendUnitTest.
*/
namespace Drupal\system\Tests\Cache;
use Drupal\Core\Cache\ChainedFastBackend;
use Drupal\Core\Cache\DatabaseBackend;
use Drupal\Core\Cache\PhpBackend;
/**
* Unit test of the fast chained backend using the generic cache unit test base.
*
* @group Cache
*/
class ChainedFastBackendUnitTest 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($this->container->get('database'), $bin);
$fast_backend = new PhpBackend($bin);
return new ChainedFastBackend($consistent_backend, $fast_backend, $bin);
}
}
......@@ -75,6 +75,8 @@ public function testFallThroughToConsistentCache() {
'cid' => 'foo',
'data' => 'baz',
'created' => time(),
'expire' => time() + 3600,
'tags' => ['tag'],
);
$consistent_cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
......@@ -101,7 +103,7 @@ public function testFallThroughToConsistentCache() {
// We should get a call to set the cache item on the fast backend.
$fast_cache->expects($this->once())
->method('set')
->with($cache_item->cid, $cache_item->data);
->with($cache_item->cid, $cache_item->data, $cache_item->expire, $cache_item->tags);
$chained_fast_backend = new ChainedFastBackend(
$consistent_cache,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment