Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit99a8f3b

Browse files
[Cache] Tell about namespace-based invalidation
1 parent32fab7e commit99a8f3b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎components/cache.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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

89116
Stampede Prevention

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp