Skip to content

Commit a9220f2

Browse files
committed
Document how to create cache pool with framework config
1 parent bf417ea commit a9220f2

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

cache.rst

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ You can also create more customized pools:
230230
<framework:pool name="my_cache_pool" adapter="cache.adapter.array"/>
231231
<framework:pool name="acme.cache" adapter="cache.adapter.memcached"/>
232232
<framework:pool name="foobar.cache" adapter="cache.adapter.memcached" provider="memcached://user:[email protected]"/>
233-
<framework:pool name="short_cache" adapter="foobar.cache" default_lifetime="60"/>
233+
<framework:pool name="short_cache" adapter="foobar.cache" default-lifetime="60"/>
234234
</framework:cache>
235235
</framework:config>
236236
</container>
@@ -376,6 +376,10 @@ To get the best of both worlds you may use a chain of adapters. The idea is to
376376
first look at the quick adapter and then move on to slower adapters. In the worst
377377
case the value needs to be recalculated.
378378

379+
.. versionadded:: 4.4
380+
381+
Support for configure a chain using ``framework.cache.pools`` was introduced in Symfony 4.4.
382+
379383
.. configuration-block::
380384

381385
.. code-block:: yaml
@@ -385,23 +389,15 @@ case the value needs to be recalculated.
385389
cache:
386390
pools:
387391
my_cache_pool:
388-
adapter: cache.adapter.psr6
389-
provider: app.my_cache_chain_adapter
392+
default_lifetime: 31536000 # One year
393+
adapters:
394+
- cache.adapter.array
395+
- cache.adapter.apcu
396+
- cache.my_redis
397+
390398
cache.my_redis:
391399
adapter: cache.adapter.redis
392400
provider: 'redis://user:[email protected]'
393-
cache.apcu:
394-
adapter: cache.adapter.apcu
395-
cache.array:
396-
adapter: cache.adapter.array
397-
398-
399-
services:
400-
app.my_cache_chain_adapter:
401-
class: Symfony\Component\Cache\Adapter\ChainAdapter
402-
arguments:
403-
- ['@cache.array', '@cache.apcu', '@cache.my_redis']
404-
- 31536000 # One year
405401
406402
.. code-block:: xml
407403
@@ -415,23 +411,13 @@ case the value needs to be recalculated.
415411
416412
<framework:config>
417413
<framework:cache>
418-
<framework:pool name="my_cache_pool" adapter="cache.adapter.psr6" provider="app.my_cache_chain_adapter"/>
419-
<framework:pool name="cache.my_redis" adapter="cache.adapter.redis" provider="redis://user:[email protected]"/>
420-
<framework:pool name="cache.apcu" adapter="cache.adapter.apcu"/>
421-
<framework:pool name="cache.array" adapter="cache.adapter.array"/>
414+
<framework:pool name="my_cache_pool" default-lifetime="31536000">
415+
<framework:adapter name="cache.adapter.array" />
416+
<framework:adapter name="cache.adapter.apcu" />
417+
<framework:adapter name="cache.adapter.redis" provider="app.cache.provider.redis" />
418+
</framework:pool>
422419
</framework:cache>
423420
</framework:config>
424-
425-
<services>
426-
<service id="app.my_cache_chain_adapter" class="Symfony\Component\Cache\Adapter\ChainAdapter">
427-
<argument type="collection">
428-
<argument type="service" value="cache.array"/>
429-
<argument type="service" value="cache.apcu"/>
430-
<argument type="service" value="cache.my_redis"/>
431-
</argument>
432-
<argument>31536000</argument>
433-
</service>
434-
</services>
435421
</container>
436422
437423
.. code-block:: php
@@ -441,31 +427,21 @@ case the value needs to be recalculated.
441427
'cache' => [
442428
'pools' => [
443429
'my_cache_pool' => [
444-
'adapter' => 'cache.adapter.psr6',
445-
'provider' => 'app.my_cache_chain_adapter',
430+
'default_lifetime' => 31536000, // One year
431+
'adapters' => [
432+
'cache.adapter.array',
433+
'cache.adapter.apcu',
434+
'cache.my_redis',
435+
],
446436
],
447437
'cache.my_redis' => [
448438
'adapter' => 'cache.adapter.redis',
449439
'provider' => 'redis://user:[email protected]',
450440
],
451-
'cache.apcu' => [
452-
'adapter' => 'cache.adapter.apcu',
453-
],
454-
'cache.array' => [
455-
'adapter' => 'cache.adapter.array',
456-
],
457441
],
458442
],
459443
]);
460444
461-
$container->getDefinition('app.my_cache_chain_adapter', \Symfony\Component\Cache\Adapter\ChainAdapter::class)
462-
->addArgument([
463-
new Reference('cache.array'),
464-
new Reference('cache.apcu'),
465-
new Reference('cache.my_redis'),
466-
])
467-
->addArgument(31536000);
468-
469445
.. note::
470446

471447
In this configuration the ``my_cache_pool`` pool is using the ``cache.adapter.psr6``

0 commit comments

Comments
 (0)