diff --git a/core/lib/Drupal/Core/Cache/MultiBackend.php b/core/lib/Drupal/Core/Cache/MultiBackend.php index f5c5d92..5900622 100644 --- a/core/lib/Drupal/Core/Cache/MultiBackend.php +++ b/core/lib/Drupal/Core/Cache/MultiBackend.php @@ -68,7 +68,9 @@ public function __construct(CacheBackendInterface $cache_backend, $bin) { * {@inheritdoc} */ public function get($cid, $allow_invalid = FALSE) { - return isset($this->cacheItems[$cid]) ? $this->prepareItem($this->cacheItems[$cid], $allow_invalid) : FALSE; + // Try to get the cache item from the preloaded data, otherwise delegate to + // the storage backend. + return isset($this->cacheItems[$cid]) ? $this->prepareItem($this->cacheItems[$cid], $allow_invalid) : $this->cacheBackend->get($cid, $allow_invalid); } /** @@ -87,6 +89,14 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) { $cids = array_diff($cids, array_keys($ret)); + if ($cids) { + foreach ($this->cacheBackend->getMultiple($cids, $allow_invalid) as $item) { + $ret[$item->cid] = $item; + } + + $cids = array_diff($cids, array_keys($ret)); + } + return $ret; } @@ -94,28 +104,28 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) { * {@inheritdoc} */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { - $this->cacheItems[$cid] = $this->createCacheObject($cid, $data, $expire, $tags); + $this->cacheBackend->set($cid, $data, $expire, $tags); - $return = $this->cacheBackend->set($cid, $data, $expire, $tags); + $this->cacheItems[$cid] = $this->createCacheObject($cid, $data, $expire, $tags); $this->addMultiKeys([$cid]); - - return $return; } /** * {@inheritdoc} */ public function setMultiple(array $items = []) { + $this->cacheBackend->setMultiple($items); + foreach ($items as $cid => $item) { - $this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : []); + $item += [ + 'expire' => Cache::PERMANENT, + 'tags' => [], + ]; + $this->cacheItems[$cid] = $this->createCacheObject($cid, $item['data'], $item['expire'], $item['tags']); } - $return = $this->cacheBackend->setMultiple($items); - // Map keys and store them. $this->addMultiKeys(array_keys($items)); - - return $return; } /** @@ -187,7 +197,7 @@ public function invalidateAll() { } /** - * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). + * {@inheritdoc} */ public function invalidateTags(array $tags) { foreach ($this->cacheItems as $cid => $item) { @@ -267,7 +277,7 @@ protected function prepareItem($cache, $allow_invalid) { } // Check expire time. - $prepared->valid = $prepared->expire == Cache::PERMANENT || $prepared->expire >= $this->getRequestTime(); + $prepared->valid = ($prepared->expire === Cache::PERMANENT) || ($prepared->expire >= $this->getRequestTime()); if (!$allow_invalid && !$prepared->valid) { return FALSE; @@ -277,7 +287,7 @@ protected function prepareItem($cache, $allow_invalid) { } /** - * Adds a mutli cache key. + * Adds a multi cache key. * * @param array $keys */ @@ -326,9 +336,9 @@ protected function createCacheObject($cid, $data, $expire = Cache::PERMANENT, ar 'cid' => $cid, 'data' => is_object($data) ? clone $data : $data, 'expire' => $expire, - 'created' => $this->getRequestTime(), + 'created' => round(microtime(TRUE), 3), 'tags' => $tags, - 'valid' => $expire == Cache::PERMANENT || $expire >= $this->getRequestTime(), + 'serialized' => FALSE, ]; } diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index 6b915e6..6346fb8 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -7,10 +7,10 @@ services: arguments: [access, '@container.namespaces', '@cache.views_plugin', '@module_handler'] plugin.manager.views.area: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [area, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [area, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.argument: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [argument, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [argument, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.argument_default: class: Drupal\views\Plugin\ViewsPluginManager arguments: [argument_default, '@container.namespaces', '@cache.views_plugin', '@module_handler'] @@ -31,28 +31,28 @@ services: arguments: [exposed_form, '@container.namespaces', '@cache.views_plugin', '@module_handler'] plugin.manager.views.field: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [field, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [field, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.filter: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [filter, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [filter, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.join: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [join, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [join, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.pager: class: Drupal\views\Plugin\ViewsPluginManager arguments: [pager, '@container.namespaces', '@cache.views_plugin', '@module_handler'] plugin.manager.views.query: class: Drupal\views\Plugin\ViewsPluginManager - arguments: [query, '@container.namespaces', '@cache.discovery', '@module_handler'] + arguments: [query, '@container.namespaces', '@cache.views_plugin', '@module_handler'] plugin.manager.views.relationship: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [relationship, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [relationship, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.row: class: Drupal\views\Plugin\ViewsPluginManager arguments: [row, '@container.namespaces', '@cache.views_plugin', '@module_handler'] plugin.manager.views.sort: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [sort, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [sort, '@container.namespaces', '@views.views_data', '@cache.views_plugin', '@module_handler'] plugin.manager.views.style: class: Drupal\views\Plugin\ViewsPluginManager arguments: [style, '@container.namespaces', '@cache.views_plugin', '@module_handler']