diff --git a/cache.rst b/cache.rst index 49c5bfa8854..79270a00abf 100644 --- a/cache.rst +++ b/cache.rst @@ -37,7 +37,9 @@ of: **Adapter** An adapter is a *template* that you use to create Pools. **Provider** - A provider is the DSN connection to the actual storage. + A provider is a service that some adapters are using to connect to the storage. + Redis and Memcached are example of such adapters. If a DSN is used as the + provider then a service is automatically created. There are two pools that are always enabled by default. They are ``cache.app`` and ``cache.system``. The system cache is use for things like annotations, serializer, @@ -315,6 +317,83 @@ For advanced configurations it could sometimes be useful to use a pool as an ada ], ]); +Custom Provider Options +----------------------- + +Some providers have specific options that could be configured. The +:doc:`RedisAdapter ` allows you to create +providers with option ``timeout``, ``retry_interval`` etc. To use these options with non-default +values you need to create your own ``\Redis`` provider and use that when configuring +the pool. + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/cache.yaml + framework: + cache: + pools: + cache.my_redis: + adapter: cache.adapter.redis + provider: app.my_custom_redis_provider + + services: + app.my_custom_redis_provider: + class: \Redis + factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection'] + arguments: + - 'redis://localhost' + - [ retry_interval: 2, timeout: 10 ] + +.. code-block:: xml + + + + + + + + + + + + + + redis://localhost + + 2 + 10 + + + + + + .. code-block:: php + + // config/packages/cache.php + $container->loadFromExtension('framework', [ + 'cache' => [ + 'pools' => [ + 'cache.my_redis' => [ + 'adapter' => 'cache.adapter.redis', + 'provider' => 'app.my_custom_redis_provider', + ], + ], + ], + ]); + + $container->getDefinition('app.my_custom_redis_provider', \Redis::class) + ->addArgument('redis://localhost') + ->addArgument([ + 'retry_interval' => 2, + 'timeout' => 10 + ]); + Creating a Cache Chain ----------------------