diff --git a/core/lib/Drupal/Core/Cache/CacheBackendPass.php b/core/lib/Drupal/Core/Cache/CacheBackendPass.php index c907c930b7..21117d39fd 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendPass.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendPass.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** + * Container pass to provide a BC layer for cache backends automatically. */ class CacheBackendPass implements CompilerPassInterface { diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index 9440352ae1..a6e45bb0f9 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -34,6 +34,8 @@ class CacheFactory implements CacheFactoryInterface, ContainerAwareInterface { protected $defaultBinBackends; /** + * A list of cache backends without a BC layer. + * * @var string[] */ protected $cacheBackendsWithNonLegacy; @@ -47,7 +49,7 @@ class CacheFactory implements CacheFactoryInterface, ContainerAwareInterface { * (optional) A mapping of bin to backend service name. Mappings in * $settings take precedence over this. * @param array $cache_backends_non_legacy - * (optional) + * (optional) A list of cache backends without a BC layer. */ public function __construct(Settings $settings, array $default_bin_backends = [], array $cache_backends_non_legacy = []) { $this->settings = $settings; diff --git a/core/lib/Drupal/Core/Cache/CacheItem.php b/core/lib/Drupal/Core/Cache/CacheItem.php index e0fcb86253..e018feeb43 100644 --- a/core/lib/Drupal/Core/Cache/CacheItem.php +++ b/core/lib/Drupal/Core/Cache/CacheItem.php @@ -131,9 +131,7 @@ public function isExpired() { if (CacheBackendInterface::CACHE_PERMANENT === $this->expire) { return FALSE; } - else { - return \Drupal::time()->getCurrentTime() >= $this->expire; - } + return \Drupal::time()->getCurrentTime() >= $this->expire; } /** diff --git a/core/lib/Drupal/Core/Cache/CacheItemCacheBackendDecorator.php b/core/lib/Drupal/Core/Cache/CacheItemCacheBackendDecorator.php index d8da929d77..7838ce3c8d 100644 --- a/core/lib/Drupal/Core/Cache/CacheItemCacheBackendDecorator.php +++ b/core/lib/Drupal/Core/Cache/CacheItemCacheBackendDecorator.php @@ -2,9 +2,14 @@ namespace Drupal\Core\Cache; +/** + * Decorates a cache backend to ensure it always returns CachItem objects. + */ class CacheItemCacheBackendDecorator implements CacheBackendInterface { /** + * The wrapped cache backend. + * * @var \Drupal\Core\Cache\CacheBackendInterface */ protected $cacheBackend; @@ -16,6 +21,16 @@ public function __construct(CacheBackendInterface $cacheBackend) { $this->cacheBackend = $cacheBackend; } + /** + * Wraps a cache result inside a CacheItem. + * + * @param string $cid + * The cache ID. + * @param \stdClass|\Drupal\Core\Cache\CacheItem $result + * The cache result + * + * @return \Drupal\Core\Cache\CacheItem|FALSE + */ protected function wrapResult($cid, $result) { if ($result instanceof CacheItem) { return $result; @@ -24,6 +39,8 @@ protected function wrapResult($cid, $result) { if ($result) { return new CacheItem($cid, $result->data, $result->expire, $result->tags, $result->created, $result->valid); } + + return FALSE; } /** @@ -49,69 +66,69 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) { * {@inheritdoc} */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) { - return $this->cacheBackend->set($cid, $data, $expire, $tags); + $this->cacheBackend->set($cid, $data, $expire, $tags); } /** * {@inheritdoc} */ public function setMultiple(array $items) { - return $this->cacheBackend->setMultiple($items); + $this->cacheBackend->setMultiple($items); } /** * {@inheritdoc} */ public function delete($cid) { - return $this->cacheBackend->delete($cid); + $this->cacheBackend->delete($cid); } /** * {@inheritdoc} */ public function deleteMultiple(array $cids) { - return $this->cacheBackend->deleteMultiple($cids); + $this->cacheBackend->deleteMultiple($cids); } /** * {@inheritdoc} */ public function deleteAll() { - return $this->cacheBackend->deleteAll(); + $this->cacheBackend->deleteAll(); } /** * {@inheritdoc} */ public function invalidate($cid) { - return $this->cacheBackend->invalidate($cid); + $this->cacheBackend->invalidate($cid); } /** * {@inheritdoc} */ public function invalidateMultiple(array $cids) { - return $this->cacheBackend->invalidateMultiple($cids); + $this->cacheBackend->invalidateMultiple($cids); } /** * {@inheritdoc} */ public function invalidateAll() { - return $this->cacheBackend->invalidateAll(); + $this->cacheBackend->invalidateAll(); } /** * {@inheritdoc} */ public function garbageCollection() { - return $this->cacheBackend->garbageCollection(); + $this->cacheBackend->garbageCollection(); } /** * {@inheritdoc} */ public function removeBin() { - return $this->cacheBackend->removeBin(); + $this->cacheBackend->removeBin(); } /** @@ -125,7 +142,7 @@ public function __get($name) { * {@inheritdoc} */ public function __set($name, $value) { - return $this->cacheBackend->{$name} = $value; + $this->cacheBackend->{$name} = $value; } /** @@ -135,4 +152,10 @@ public function __isset($name) { return isset($this->cacheBackend->{$name}); } + public function reset() { + if (method_exists($this->cacheBackend, 'reset')) { + $this->cacheBackend->reset(); + } + } + }