Verified Commit 0448b4bc authored by Dave Long's avatar Dave Long
Browse files

Issue #3334489 by catch, Berdir, longwave, andypost: ChainedFastBackend...

Issue #3334489 by catch, Berdir, longwave, andypost: ChainedFastBackend invalidates all items when cache tags are invalidated
parent fc024f35
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -12,7 +12,9 @@
 * item. The fast backend will also typically be inconsistent (will only see
 * changes from one web node). The slower backend will be something like Mysql,
 * Memcached or Redis, and will be used by all web nodes, thus making it
 * consistent, but also require a network round trip for each cache get.
 * consistent, but also require a network round trip for each cache get. The
 * fast backend must however also use a consistent cache tag invalidation, for
 * example by using the cache tag checksum API.
 *
 * In addition to being useful for sites running on multiple web nodes, this
 * backend can also be useful for sites running on a single web node where the
@@ -164,9 +166,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
    if ($cids) {
      foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) {
        $cache[$item->cid] = $item;
        // Don't write the cache tags to the fast backend as any cache tag
        // invalidation results in an invalidation of the whole fast backend.
        $this->fastBackend->set($item->cid, $item->data, $item->expire);
        $this->fastBackend->set($item->cid, $item->data, $item->expire, $item->tags);
      }
    }

@@ -179,9 +179,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
  public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
    $this->consistentBackend->set($cid, $data, $expire, $tags);
    $this->markAsOutdated();
    // Don't write the cache tags to the fast backend as any cache tag
    // invalidation results in an invalidation of the whole fast backend.
    $this->fastBackend->set($cid, $data, $expire);
    $this->fastBackend->set($cid, $data, $expire, $tags);
  }

  /**
@@ -190,11 +188,6 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
  public function setMultiple(array $items) {
    $this->consistentBackend->setMultiple($items);
    $this->markAsOutdated();
    // Don't write the cache tags to the fast backend as any cache tag
    // invalidation results in an invalidation of the whole fast backend.
    foreach ($items as &$item) {
      unset($item['tags']);
    }
    $this->fastBackend->setMultiple($items);
  }

@@ -244,7 +237,9 @@ public function invalidateTags(array $tags) {
    if ($this->consistentBackend instanceof CacheTagsInvalidatorInterface) {
      $this->consistentBackend->invalidateTags($tags);
    }
    $this->markAsOutdated();
    if ($this->fastBackend instanceof CacheTagsInvalidatorInterface) {
      $this->fastBackend->invalidateTags($tags);
    }
  }

  /**