From d6e899115739150e94baa92bda93fe71bd849e67 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 8 Apr 2019 18:44:18 +0200 Subject: [PATCH 1/5] Show how to configure redis provider --- cache.rst | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/cache.rst b/cache.rst index 49c5bfa8854..6c98cbd7172 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,85 @@ 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 do create +providers with option ``lazy`` and ``timeout`` 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' + - [ lazy: true, timeout: 10 ] + +.. code-block:: xml + + + + + + + + + + + + + + redis://localhost + + true + 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', + [ 'lazy' => true, 'timeout' => 10 ], + ]) + ->addArgument(31536000); + Creating a Cache Chain ---------------------- From 60bbddb90ef89083ac0dfdc3a69c94e9547e3ab0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 8 Apr 2019 18:46:24 +0200 Subject: [PATCH 2/5] minors --- cache.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cache.rst b/cache.rst index 6c98cbd7172..57823b98115 100644 --- a/cache.rst +++ b/cache.rst @@ -317,7 +317,7 @@ For advanced configurations it could sometimes be useful to use a pool as an ada ], ]); -Custom provider options +Custom Provider Options ----------------------- Some providers have specific options that could be configured. The @@ -332,7 +332,6 @@ the pool. .. code-block:: yaml # config/packages/cache.yaml - framework: cache: pools: From 605763c7e542b001b8cc9eda617f189358a3cf92 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 8 Apr 2019 18:51:36 +0200 Subject: [PATCH 3/5] minor fixes --- cache.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cache.rst b/cache.rst index 57823b98115..e58559412d5 100644 --- a/cache.rst +++ b/cache.rst @@ -321,12 +321,11 @@ Custom Provider Options ----------------------- Some providers have specific options that could be configured. The -:doc:`RedisAdapter ` allows you do create -providers with option ``lazy`` and ``timeout`` etc. To use these options with non-default +:doc:`RedisAdapter ` allows you to create +providers with option ``lazy``, ``timeout`` 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 @@ -389,11 +388,11 @@ the pool. ]); $container->getDefinition('app.my_custom_redis_provider', \Redis::class) + ->addArgument('redis://localhost') ->addArgument([ - 'redis://localhost', - [ 'lazy' => true, 'timeout' => 10 ], - ]) - ->addArgument(31536000); + 'lazy' => true, + 'timeout' => 10 + ]); Creating a Cache Chain ---------------------- From c7f8c01ec4972736256a68980febb5adf6980e1f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 8 Apr 2019 19:12:38 +0200 Subject: [PATCH 4/5] Use "retry_interval" --- cache.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cache.rst b/cache.rst index e58559412d5..903e8ac81f8 100644 --- a/cache.rst +++ b/cache.rst @@ -322,7 +322,7 @@ Custom Provider Options Some providers have specific options that could be configured. The :doc:`RedisAdapter ` allows you to create -providers with option ``lazy``, ``timeout`` etc. To use these options with non-default +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. @@ -344,7 +344,7 @@ the pool. factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection'] arguments: - 'redis://localhost' - - [ lazy: true, timeout: 10 ] + - [ retry_interval: 2, timeout: 10 ] .. code-block:: xml @@ -366,7 +366,7 @@ the pool. redis://localhost - true + 2 10 @@ -390,7 +390,7 @@ the pool. $container->getDefinition('app.my_custom_redis_provider', \Redis::class) ->addArgument('redis://localhost') ->addArgument([ - 'lazy' => true, + 'retry_interval' => 2, 'timeout' => 10 ]); From 6b62150c7fd8e8469adfa32373e738183305e009 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 9 Apr 2019 16:22:52 +0200 Subject: [PATCH 5/5] Use "key" --- cache.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.rst b/cache.rst index 903e8ac81f8..79270a00abf 100644 --- a/cache.rst +++ b/cache.rst @@ -366,8 +366,8 @@ the pool. redis://localhost - 2 - 10 + 2 + 10