Skip to content

Commit 4b4e8e7

Browse files
committed
RedisTagAwareAdapter integration
1 parent 52c2ca0 commit 4b4e8e7

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

cache.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ The Cache component comes with a series of adapters pre-configured:
102102
* :doc:`cache.adapter.pdo </components/cache/adapters/pdo_doctrine_dbal_adapter>`
103103
* :doc:`cache.adapter.psr6 </components/cache/adapters/proxy_adapter>`
104104
* :doc:`cache.adapter.redis </components/cache/adapters/redis_adapter>`
105+
* :ref:`cache.adapter.redis_tag_aware <redis-tag-aware>` (Redis adapter optimized to work with tags)
106+
107+
.. versionadded:: 5.2
108+
109+
`cache.adapter.redis_tag_aware` has been introduced in Symfony 5.2.
105110

106111
Some of these adapters could be configured via shortcuts. Using these shortcuts
107112
will create pools with service IDs that follow the pattern ``cache.[type]``.

components/cache/adapters/redis_adapter.rst

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

183+
.. _redis-tag-aware:
184+
185+
Working with tags
186+
-----------------
187+
188+
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::
189+
190+
use Symfony\Component\Cache\Adapter\RedisAdapter;
191+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
192+
193+
$client = RedisAdapter::createConnection('redis://localhost');
194+
$cache = new TagAwareAdapter($client);
195+
196+
183197
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
184198
.. _`Redis server`: https://redis.io/
185199
.. _`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)