From 3178aed84e4c3a4863447f602df0d8de364473ba Mon Sep 17 00:00:00 2001 From: Pierre Rineau Date: Tue, 26 Jun 2018 16:07:07 +0200 Subject: [PATCH] [Cache] ArrayAdapter and NullAdapter don't need stampede protection --- .../Component/Cache/Adapter/ArrayAdapter.php | 17 +++++++++++++++-- .../Component/Cache/Adapter/NullAdapter.php | 11 ++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index 1c272c76ab..92d9d09c3e 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -17,7 +17,6 @@ use Symfony\Component\Cache\CacheInterface; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\ResettableInterface; use Symfony\Component\Cache\Traits\ArrayTrait; -use Symfony\Component\Cache\Traits\GetTrait; /** * @author Nicolas Grekas @@ -25,7 +24,6 @@ use Symfony\Component\Cache\Traits\GetTrait; class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface { use ArrayTrait; - use GetTrait; private $createCacheItem; @@ -51,6 +49,21 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter ); } + /** + * {@inheritdoc} + */ + public function get(string $key, callable $callback, float $beta = null) + { + $item = $this->getItem($key); + + // ArrayAdapter works in memory, we don't care about stampede protection + if (INF === $beta || !$item->isHit()) { + $this->save($item->set($callback($item))); + } + + return $item->get(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Cache/Adapter/NullAdapter.php b/src/Symfony/Component/Cache/Adapter/NullAdapter.php index 44929f9e76..d4e7598f33 100644 --- a/src/Symfony/Component/Cache/Adapter/NullAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/NullAdapter.php @@ -14,15 +14,12 @@ namespace Symfony\Component\Cache\Adapter; use Psr\Cache\CacheItemInterface; use Symfony\Component\Cache\CacheInterface; use Symfony\Component\Cache\CacheItem; -use Symfony\Component\Cache\Traits\GetTrait; /** * @author Titouan Galopin */ class NullAdapter implements AdapterInterface, CacheInterface { - use GetTrait; - private $createCacheItem; public function __construct() @@ -40,6 +37,14 @@ class NullAdapter implements AdapterInterface, CacheInterface ); } + /** + * {@inheritdoc} + */ + public function get(string $key, callable $callback, float $beta = null) + { + return $callback(($this->createCacheItem)()); + } + /** * {@inheritdoc} */