Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a15a816

Browse filesBrowse files
committed
Merge branch '4.2'
* 4.2: [Cache] Show how to configure redis provider
2 parents 6b404e2 + 2956eda commit a15a816
Copy full SHA for a15a816

File tree

1 file changed

+80
-1
lines changed
Filter options

1 file changed

+80
-1
lines changed

‎cache.rst

Copy file name to clipboardExpand all lines: cache.rst
+80-1Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ of:
4646
**Adapter**
4747
An adapter is a *template* that you use to create Pools.
4848
**Provider**
49-
A provider is the DSN connection to the actual storage.
49+
A provider is a service that some adapters are using to connect to the storage.
50+
Redis and Memcached are example of such adapters. If a DSN is used as the
51+
provider then a service is automatically created.
5052

5153
There are two pools that are always enabled by default. They are ``cache.app`` and
5254
``cache.system``. The system cache is use for things like annotations, serializer,
@@ -324,6 +326,83 @@ For advanced configurations it could sometimes be useful to use a pool as an ada
324326
],
325327
]);
326328
329+
Custom Provider Options
330+
-----------------------
331+
332+
Some providers have specific options that could be configured. The
333+
:doc:`RedisAdapter </components/cache/adapters/redis_adapter>` allows you to
334+
create providers with option ``timeout``, ``retry_interval``. etc. To use these
335+
options with non-default values you need to create your own ``\Redis`` provider
336+
and use that when configuring the pool.
337+
338+
.. configuration-block::
339+
340+
.. code-block:: yaml
341+
342+
# config/packages/cache.yaml
343+
framework:
344+
cache:
345+
pools:
346+
cache.my_redis:
347+
adapter: cache.adapter.redis
348+
provider: app.my_custom_redis_provider
349+
350+
services:
351+
app.my_custom_redis_provider:
352+
class: \Redis
353+
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
354+
arguments:
355+
- 'redis://localhost'
356+
- [ retry_interval: 2, timeout: 10 ]
357+
358+
.. code-block:: xml
359+
360+
<!-- config/packages/cache.xml -->
361+
<?xml version="1.0" encoding="UTF-8" ?>
362+
<container xmlns="http://symfony.com/schema/dic/services"
363+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
364+
xmlns:framework="http://symfony.com/schema/dic/symfony"
365+
xsi:schemaLocation="http://symfony.com/schema/dic/services
366+
https://symfony.com/schema/dic/services/services-1.0.xsd">
367+
368+
<framework:config>
369+
<framework:cache>
370+
<framework:pool name="cache.my_redis" adapter="cache.adapter.redis" provider="app.my_custom_redis_provider"/>
371+
</framework:cache>
372+
</framework:config>
373+
374+
<services>
375+
<service id="app.my_custom_redis_provider" class="\Redis">
376+
<argument>redis://localhost</argument>
377+
<argument type="collection">
378+
<argument key="retry_interval">2</argument>
379+
<argument key="timeout">10</argument>
380+
</argument>
381+
</service>
382+
</services>
383+
</container>
384+
385+
.. code-block:: php
386+
387+
// config/packages/cache.php
388+
$container->loadFromExtension('framework', [
389+
'cache' => [
390+
'pools' => [
391+
'cache.my_redis' => [
392+
'adapter' => 'cache.adapter.redis',
393+
'provider' => 'app.my_custom_redis_provider',
394+
],
395+
],
396+
],
397+
]);
398+
399+
$container->getDefinition('app.my_custom_redis_provider', \Redis::class)
400+
->addArgument('redis://localhost')
401+
->addArgument([
402+
'retry_interval' => 2,
403+
'timeout' => 10
404+
]);
405+
327406
Creating a Cache Chain
328407
----------------------
329408

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.