Permalink
Browse files

bug #27734 [Cache] ArrayAdapter and NullAdapter don't need stampede p…

…rotection (Pierre Rineau)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Cache] ArrayAdapter and NullAdapter don't need stampede protection

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | probably
| Fixed tickets | #27734 #27731
| License       | MIT

Cf. issues.

Commits
-------

3178aed [Cache] ArrayAdapter and NullAdapter don't need stampede protection
  • Loading branch information...
nicolas-grekas committed Jun 28, 2018
2 parents adb137d + 3178aed commit 17977c8d0c5bc744af00a22fce77a01ab278b930
@@ -17,15 +17,13 @@
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>
*/
class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
{
use ArrayTrait;
use GetTrait;
private $createCacheItem;
@@ -51,6 +49,21 @@ function ($key, $value, $isHit) use ($defaultLifetime) {
);
}
/**
* {@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 @@
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 @@ function ($key) {
);
}
/**
* {@inheritdoc}
*/
public function get(string $key, callable $callback, float $beta = null)
{
return $callback(($this->createCacheItem)());
}
/**
* {@inheritdoc}
*/

0 comments on commit 17977c8

Please sign in to comment.