Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c0a052

Browse filesBrowse files
feature #24226 [Cache] Add ResettableInterface to allow resetting any pool's local state (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Cache] Add ResettableInterface to allow resetting any pool's local state | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - To allow pools to leverage #24155 so that they can be used in multi-request loops. Commits ------- 14c91f2 [Cache] Add ResettableInterface to allow resetting any pool's local state
2 parents f617882 + 14c91f2 commit 0c0a052
Copy full SHA for 0c0a052
Expand file treeCollapse file tree

33 files changed

+315
-70
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function process(ContainerBuilder $container)
4343
'provider',
4444
'namespace',
4545
'default_lifetime',
46+
'reset',
4647
);
4748
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $tags) {
4849
$adapter = $pool = $container->getDefinition($id);
@@ -73,13 +74,19 @@ public function process(ContainerBuilder $container)
7374
}
7475
$i = 0;
7576
foreach ($attributes as $attr) {
76-
if (isset($tags[0][$attr]) && ('namespace' !== $attr || ArrayAdapter::class !== $adapter->getClass())) {
77+
if (!isset($tags[0][$attr])) {
78+
// no-op
79+
} elseif ('reset' === $attr) {
80+
if ($tags[0][$attr]) {
81+
$pool->addTag('kernel.reset', array('method' => $tags[0][$attr]));
82+
}
83+
} elseif ('namespace' !== $attr || ArrayAdapter::class !== $adapter->getClass()) {
7784
$pool->replaceArgument($i++, $tags[0][$attr]);
7885
}
7986
unset($tags[0][$attr]);
8087
}
8188
if (!empty($tags[0])) {
82-
throw new InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace" and "default_lifetime", found "%s".', $id, implode('", "', array_keys($tags[0]))));
89+
throw new InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace", "default_lifetime" and "reset", found "%s".', $id, implode('", "', array_keys($tags[0]))));
8390
}
8491

8592
if (null !== $clearer) {

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
2626
use Symfony\Component\Cache\Adapter\AdapterInterface;
2727
use Symfony\Component\Cache\Adapter\ArrayAdapter;
28+
use Symfony\Component\Cache\ResettableInterface;
2829
use Symfony\Component\Config\FileLocator;
2930
use Symfony\Component\Config\Loader\LoaderInterface;
3031
use Symfony\Component\Config\Resource\DirectoryResource;
@@ -339,6 +340,8 @@ public function load(array $configs, ContainerBuilder $container)
339340
->addTag('kernel.cache_warmer');
340341
$container->registerForAutoconfiguration(EventSubscriberInterface::class)
341342
->addTag('kernel.event_subscriber');
343+
$container->registerForAutoconfiguration(ResettableInterface::class)
344+
->addTag('kernel.reset', array('method' => 'reset'));
342345
$container->registerForAutoconfiguration(PropertyListExtractorInterface::class)
343346
->addTag('property_info.list_extractor');
344347
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<defaults public="false" />
99

1010
<service id="cache.app" parent="cache.adapter.filesystem" public="true">
11-
<tag name="cache.pool" clearer="cache.app_clearer" />
11+
<tag name="cache.pool" clearer="cache.app_clearer" reset="reset" />
1212
</service>
1313

1414
<service id="cache.system" parent="cache.adapter.system" public="true">
@@ -90,7 +90,7 @@
9090
</service>
9191

9292
<service id="cache.adapter.memcached" class="Symfony\Component\Cache\Adapter\MemcachedAdapter" abstract="true">
93-
<tag name="cache.pool" provider="cache.default_memcached_provider" clearer="cache.default_clearer" />
93+
<tag name="cache.pool" provider="cache.default_memcached_provider" clearer="cache.default_clearer" reset="reset" />
9494
<tag name="monolog.logger" channel="cache" />
9595
<argument /> <!-- Memcached connection service -->
9696
<argument /> <!-- namespace -->

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
use Psr\Log\NullLogger;
1818
use Symfony\Component\Cache\CacheItem;
1919
use Symfony\Component\Cache\Exception\InvalidArgumentException;
20+
use Symfony\Component\Cache\ResettableInterface;
2021
use Symfony\Component\Cache\Traits\AbstractTrait;
2122

2223
/**
2324
* @author Nicolas Grekas <p@tchwork.com>
2425
*/
25-
abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
26+
abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface, ResettableInterface
2627
{
2728
use AbstractTrait;
2829

‎src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Log\LoggerAwareInterface;
1616
use Symfony\Component\Cache\CacheItem;
17+
use Symfony\Component\Cache\ResettableInterface;
1718
use Symfony\Component\Cache\Traits\ArrayTrait;
1819

1920
/**
2021
* @author Nicolas Grekas <p@tchwork.com>
2122
*/
22-
class ArrayAdapter implements AdapterInterface, LoggerAwareInterface
23+
class ArrayAdapter implements AdapterInterface, LoggerAwareInterface, ResettableInterface
2324
{
2425
use ArrayTrait;
2526

‎src/Symfony/Component/Cache/Adapter/ChainAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ChainAdapter.php
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Cache\CacheItem;
1717
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1818
use Symfony\Component\Cache\PruneableInterface;
19+
use Symfony\Component\Cache\ResettableInterface;
1920

2021
/**
2122
* Chains several adapters together.
@@ -25,7 +26,7 @@
2526
*
2627
* @author Kévin Dunglas <dunglas@gmail.com>
2728
*/
28-
class ChainAdapter implements AdapterInterface, PruneableInterface
29+
class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableInterface
2930
{
3031
private $adapters = array();
3132
private $adapterCount;
@@ -248,4 +249,16 @@ public function prune()
248249

249250
return $pruned;
250251
}
252+
253+
/**
254+
* {@inheritdoc}
255+
*/
256+
public function reset()
257+
{
258+
foreach ($this->adapters as $adapter) {
259+
if ($adapter instanceof ResettableInterface) {
260+
$adapter->reset();
261+
}
262+
}
263+
}
251264
}

‎src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Psr\Cache\CacheItemPoolInterface;
1616
use Symfony\Component\Cache\CacheItem;
1717
use Symfony\Component\Cache\Exception\InvalidArgumentException;
18+
use Symfony\Component\Cache\PruneableInterface;
19+
use Symfony\Component\Cache\ResettableInterface;
1820
use Symfony\Component\Cache\Traits\PhpArrayTrait;
1921

2022
/**
@@ -24,7 +26,7 @@
2426
* @author Titouan Galopin <galopintitouan@gmail.com>
2527
* @author Nicolas Grekas <p@tchwork.com>
2628
*/
27-
class PhpArrayAdapter implements AdapterInterface
29+
class PhpArrayAdapter implements AdapterInterface, PruneableInterface, ResettableInterface
2830
{
2931
use PhpArrayTrait;
3032

@@ -37,7 +39,7 @@ class PhpArrayAdapter implements AdapterInterface
3739
public function __construct($file, AdapterInterface $fallbackPool)
3840
{
3941
$this->file = $file;
40-
$this->fallbackPool = $fallbackPool;
42+
$this->pool = $fallbackPool;
4143
$this->zendDetectUnicode = ini_get('zend.detect_unicode');
4244
$this->createCacheItem = \Closure::bind(
4345
function ($key, $value, $isHit) {
@@ -89,7 +91,7 @@ public function getItem($key)
8991
$this->initialize();
9092
}
9193
if (!isset($this->values[$key])) {
92-
return $this->fallbackPool->getItem($key);
94+
return $this->pool->getItem($key);
9395
}
9496

9597
$value = $this->values[$key];
@@ -144,7 +146,7 @@ public function hasItem($key)
144146
$this->initialize();
145147
}
146148

147-
return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
149+
return isset($this->values[$key]) || $this->pool->hasItem($key);
148150
}
149151

150152
/**
@@ -159,7 +161,7 @@ public function deleteItem($key)
159161
$this->initialize();
160162
}
161163

162-
return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
164+
return !isset($this->values[$key]) && $this->pool->deleteItem($key);
163165
}
164166

165167
/**
@@ -186,7 +188,7 @@ public function deleteItems(array $keys)
186188
}
187189

188190
if ($fallbackKeys) {
189-
$deleted = $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
191+
$deleted = $this->pool->deleteItems($fallbackKeys) && $deleted;
190192
}
191193

192194
return $deleted;
@@ -201,7 +203,7 @@ public function save(CacheItemInterface $item)
201203
$this->initialize();
202204
}
203205

204-
return !isset($this->values[$item->getKey()]) && $this->fallbackPool->save($item);
206+
return !isset($this->values[$item->getKey()]) && $this->pool->save($item);
205207
}
206208

207209
/**
@@ -213,15 +215,15 @@ public function saveDeferred(CacheItemInterface $item)
213215
$this->initialize();
214216
}
215217

216-
return !isset($this->values[$item->getKey()]) && $this->fallbackPool->saveDeferred($item);
218+
return !isset($this->values[$item->getKey()]) && $this->pool->saveDeferred($item);
217219
}
218220

219221
/**
220222
* {@inheritdoc}
221223
*/
222224
public function commit()
223225
{
224-
return $this->fallbackPool->commit();
226+
return $this->pool->commit();
225227
}
226228

227229
/**
@@ -259,7 +261,7 @@ private function generateItems(array $keys)
259261
}
260262

261263
if ($fallbackKeys) {
262-
foreach ($this->fallbackPool->getItems($fallbackKeys) as $key => $item) {
264+
foreach ($this->pool->getItems($fallbackKeys) as $key => $item) {
263265
yield $key => $item;
264266
}
265267
}

‎src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
1616
use Symfony\Component\Cache\CacheItem;
17+
use Symfony\Component\Cache\PruneableInterface;
18+
use Symfony\Component\Cache\ResettableInterface;
19+
use Symfony\Component\Cache\Traits\ProxyTrait;
1720

1821
/**
1922
* @author Nicolas Grekas <p@tchwork.com>
2023
*/
21-
class ProxyAdapter implements AdapterInterface
24+
class ProxyAdapter implements AdapterInterface, PruneableInterface, ResettableInterface
2225
{
23-
private $pool;
26+
use ProxyTrait;
27+
2428
private $namespace;
2529
private $namespaceLen;
2630
private $createCacheItem;

‎src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Psr\SimpleCache\CacheInterface;
15+
use Symfony\Component\Cache\PruneableInterface;
16+
use Symfony\Component\Cache\ResettableInterface;
17+
use Symfony\Component\Cache\Traits\ProxyTrait;
1518

1619
/**
1720
* @author Nicolas Grekas <p@tchwork.com>
1821
*/
19-
class SimpleCacheAdapter extends AbstractAdapter
22+
class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
2023
{
21-
private $pool;
24+
use ProxyTrait;
25+
2226
private $miss;
2327

2428
public function __construct(CacheInterface $pool, $namespace = '', $defaultLifetime = 0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.