Skip to content

Commit 0e60316

Browse files
feature #59813 [Cache] Enable namespace-based invalidation by prefixing keys with backend-native namespace separators (nicolas-grekas)
This PR was merged into the 7.3 branch. Discussion ---------- [Cache] Enable namespace-based invalidation by prefixing keys with backend-native namespace separators | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #45599 | License | MIT This PR adds a `NamespacedPoolInterface` that describes how one can add namespace prefixes to cache pool keys. This solves #45599 by allowing to use the `:` separator for Redis: ```php $cache->withSubNamespace('some-prefix')->get($key, fn () => ...); ``` Most importantly, this enables namespace-based cache invalidation, typically with namespaces generated by hashing some context. Commits ------- 81a8cebf0ce [Cache] Enable namespace-based invalidation by prefixing keys with backend-native namespace separators
2 parents 095b60f + 7ee3ca4 commit 0e60316

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
use Symfony\Component\Yaml\Yaml;
215215
use Symfony\Contracts\Cache\CacheInterface;
216216
use Symfony\Contracts\Cache\CallbackInterface;
217+
use Symfony\Contracts\Cache\NamespacedPoolInterface;
217218
use Symfony\Contracts\Cache\TagAwareCacheInterface;
218219
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
219220
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -2601,6 +2602,10 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
26012602
$container->registerAliasForArgument($tagAwareId, TagAwareCacheInterface::class, $pool['name'] ?? $name);
26022603
$container->registerAliasForArgument($name, CacheInterface::class, $pool['name'] ?? $name);
26032604
$container->registerAliasForArgument($name, CacheItemPoolInterface::class, $pool['name'] ?? $name);
2605+
2606+
if (interface_exists(NamespacedPoolInterface::class)) {
2607+
$container->registerAliasForArgument($name, NamespacedPoolInterface::class, $pool['name'] ?? $name);
2608+
}
26042609
}
26052610

26062611
$definition->setPublic($pool['public']);

0 commit comments

Comments
 (0)