Skip to content

Commit 12ca50f

Browse files
committed
Add documentation about RedisTagAwareAdapter
1 parent 4d52670 commit 12ca50f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

components/cache/adapters/redis_adapter.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ Available Options
188188
When using the `Predis`_ library some additional Predis-specific options are available.
189189
Reference the `Predis Connection Parameters`_ documentation for more information.
190190

191+
.. _redis-tag-aware:
192+
193+
Working with tags
194+
-----------------
195+
196+
In order to use tags-based invalidation, you can wrap your adapter in :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter`. But when Redis is used as backend, it's often more interesting to use the dedicated adapter :class:`Symfony\\Component\\Cache\\Adapter\\RedisTagAwareAdapter`. Since tag invalidation logic is implemented in Redis itself, this adapter offers better performance when using tags-based invalidation::
197+
198+
use Symfony\Component\Cache\Adapter\RedisAdapter;
199+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
200+
201+
$client = RedisAdapter::createConnection('redis://localhost');
202+
$cache = new TagAwareAdapter($client);
203+
204+
191205
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
192206
.. _`Redis server`: https://redis.io/
193207
.. _`Redis`: https://github.com/phpredis/phpredis

components/cache/cache_invalidation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ To store tags, you need to wrap a cache adapter with the
5858
:method:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapterInterface::invalidateTags`
5959
method.
6060

61+
.. note::
62+
63+
When using a Redis backend, consider using :ref:`RedisTagAwareAdapter <redis-tag-aware>` that is optimized for this purpose.
64+
6165
The :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter` class implements
6266
instantaneous invalidation (time complexity is ``O(N)`` where ``N`` is the number
6367
of invalidated tags). It needs one or two cache adapters: the first required

0 commit comments

Comments
 (0)