[Cache] ArrayAdapter and NullAdapter don't need stampede protection
This commit is contained in:
parent
2b9c142f07
commit
3178aed84e
@ -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 <p@tchwork.com>
|
||||
@ -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}
|
||||
*/
|
||||
|
@ -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 <galopintitouan@gmail.com>
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user