From 83fe3d7e9016154722305c106cfb74f0f0d5cf76 Mon Sep 17 00:00:00 2001 From: Laurent VOULLEMIER Date: Sun, 16 Aug 2020 09:53:17 +0200 Subject: [PATCH] Add documentation about RedisTagAwareAdapter --- components/cache/adapters/redis_adapter.rst | 14 ++++++++++++++ components/cache/cache_invalidation.rst | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/components/cache/adapters/redis_adapter.rst b/components/cache/adapters/redis_adapter.rst index 53b28c58466..b67e70717ac 100644 --- a/components/cache/adapters/redis_adapter.rst +++ b/components/cache/adapters/redis_adapter.rst @@ -188,6 +188,20 @@ Available Options When using the `Predis`_ library some additional Predis-specific options are available. Reference the `Predis Connection Parameters`_ documentation for more information. +.. _redis-tag-aware: + +Working with Tags +----------------- + +In order to use tag-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 :class:`Symfony\\Component\\Cache\\Adapter\\RedisTagAwareAdapter`. Since tag invalidation logic is implemented in Redis itself, this adapter offers better performance when using tag-based invalidation:: + + use Symfony\Component\Cache\Adapter\RedisAdapter; + use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; + + $client = RedisAdapter::createConnection('redis://localhost'); + $cache = new RedisTagAwareAdapter($client); + + .. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name .. _`Redis server`: https://redis.io/ .. _`Redis`: https://github.com/phpredis/phpredis diff --git a/components/cache/cache_invalidation.rst b/components/cache/cache_invalidation.rst index e56153b9ce1..680fd1d28a6 100644 --- a/components/cache/cache_invalidation.rst +++ b/components/cache/cache_invalidation.rst @@ -58,6 +58,10 @@ To store tags, you need to wrap a cache adapter with the :method:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapterInterface::invalidateTags` method. +.. note:: + + When using a Redis backend, consider using :ref:`RedisTagAwareAdapter ` which is optimized for this purpose. + The :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter` class implements instantaneous invalidation (time complexity is ``O(N)`` where ``N`` is the number of invalidated tags). It needs one or two cache adapters: the first required