File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,33 @@ generate and return the value::
8484 Use cache tags to delete more than one key at the time. Read more at
8585 :doc: `/components/cache/cache_invalidation `.
8686
87+ Creating Sub-Namespaces
88+ -----------------------
89+
90+ All cache adapters provided by the component implement the
91+ :method: `Symfony\\ Contracts\\ Cache\\ NamespacedPoolInterface::withSubNamespace ` method
92+ from the :class: `Symfony\\ Contracts\\ Cache\\ NamespacedPoolInterface `.
93+
94+ .. versionadded :: 7.3
95+
96+ Support for ``NamespacedPoolInterface `` was added in Symfony 7.3.
97+
98+ This method allows namespacing cached items by transparently prefixing their keys::
99+
100+ $subCache = $cache->withSubNamespace('foo');
101+
102+ $subCache->get('my_cache_key', function (ItemInterface $item): string {
103+ $item->expiresAfter(3600);
104+
105+ return '...';
106+ });
107+
108+ In this example, cache item keyed ``my_cache_key `` will be transparently stored within
109+ the cache pool under a logical namespace called ``foo ``.
110+
111+ Sub-namespacing allows implementing namespace-based cache invalidation, where the name
112+ of a namespace is computed by hashing some context info.
113+
87114.. _cache_stampede-prevention :
88115
89116Stampede Prevention
You can’t perform that action at this time.
0 commit comments