Commit af7652d8 authored by alexpott's avatar alexpott
Browse files

Issue #2194273 by Berdir: Avoid repeated cache tag deletions.

parent 5e112d8f
......@@ -164,6 +164,14 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array
*/
protected function doSet($cid, $data, $expire, $tags) {
$flat_tags = $this->flattenTags($tags);
$deleted_tags = &drupal_static('Drupal\Core\Cache\DatabaseBackend::deletedTags', array());
// Remove tags that were already deleted during this request from the static
// cache so that another deletion for them will be correctly updated.
foreach ($flat_tags as $tag) {
if (isset($deleted_tags[$tag])) {
unset($deleted_tags[$tag]);
}
}
$checksum = $this->checksumTags($flat_tags);
$fields = array(
'serialized' => 0,
......@@ -223,7 +231,13 @@ public function deleteMultiple(array $cids) {
*/
public function deleteTags(array $tags) {
$tag_cache = &drupal_static('Drupal\Core\Cache\CacheBackendInterface::tagCache', array());
$deleted_tags = &drupal_static('Drupal\Core\Cache\DatabaseBackend::deletedTags', array());
foreach ($this->flattenTags($tags) as $tag) {
// Only delete tags once per request unless they are written again.
if (isset($deleted_tags[$tag])) {
continue;
}
$deleted_tags[$tag] = TRUE;
unset($tag_cache[$tag]);
try {
$this->connection->merge('cache_tags')
......
......@@ -1046,6 +1046,7 @@ protected function resetAll() {
protected function refreshVariables() {
// Clear the tag cache.
drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache');
drupal_static_reset('Drupal\Core\Cache\DatabaseBackend::deletedTags');
$this->container->get('config.factory')->reset();
$this->container->get('state')->resetCache();
......
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