@@ -87,14 +87,13 @@ generate and return the value::
8787Creating Sub-Namespaces
8888-----------------------
8989
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-
9490.. versionadded :: 7.3
9591
96- Support for `` NamespacedPoolInterface `` was added in Symfony 7.3.
92+ Cache sub-namespaces were introduced in Symfony 7.3.
9793
94+ All cache adapters provided by the component implement the
95+ :class: `Symfony\\ Contracts\\ Cache\\ NamespacedPoolInterface ` to provide the
96+ :method: `Symfony\\ Contracts\\ Cache\\ NamespacedPoolInterface::withSubNamespace ` method.
9897This method allows namespacing cached items by transparently prefixing their keys::
9998
10099 $subCache = $cache->withSubNamespace('foo');
@@ -105,11 +104,17 @@ This method allows namespacing cached items by transparently prefixing their key
105104 return '...';
106105 });
107106
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 ``.
107+ In this example, the cache item will use the ``my_cache_key `` key, but it will be
108+ stored internally under the ``foo `` namespace. This is handled transparently for
109+ you, so you **don't ** need to manually prefix keys like ``foo.my_cache_key ``.
110+
111+ This is useful when using namespace-based cache invalidation to isolate or
112+ invalidate a subset of cached data based on some context. Typical examples
113+ include namespacing by user ID, locale, or entity ID and hash::
110114
111- Sub-namespacing allows implementing namespace-based cache invalidation, where the name
112- of a namespace is computed by hashing some context info.
115+ $userCache = $cache->withSubNamespace((string) $userId);
116+ $localeCache = $cache->withSubNamespace($request->getLocale());
117+ $productCache = $cache->withSubNamespace($productId.'_'.$productChecksum);
113118
114119.. _cache_stampede-prevention :
115120
0 commit comments