Skip to content

Commit 4893a5d

Browse files
committed
Merge branch '4.4'
* 4.4: Document how to create cache pool with framework config
2 parents 3a3f0b8 + 707d1bd commit 4893a5d

File tree

1 file changed

+21
-61
lines changed

1 file changed

+21
-61
lines changed

cache.rst

Lines changed: 21 additions & 61 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 configuring a chain using ``framework.cache.pools`` was introduced in Symfony 4.4.
382+
379383
.. configuration-block::
380384

381385
.. code-block:: yaml
@@ -385,23 +389,11 @@ 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
390-
cache.my_redis:
391-
adapter: cache.adapter.redis
392-
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
392+
default_lifetime: 31536000 # One year
393+
adapters:
394+
- cache.adapter.array
395+
- cache.adapter.apcu
396+
- {name: cache.adapter.redis, provider: 'redis://user:[email protected]'}
405397
406398
.. code-block:: xml
407399
@@ -415,23 +407,13 @@ case the value needs to be recalculated.
415407
416408
<framework:config>
417409
<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"/>
410+
<framework:pool name="my_cache_pool" default-lifetime="31536000">
411+
<framework:adapter name="cache.adapter.array" />
412+
<framework:adapter name="cache.adapter.apcu" />
413+
<framework:adapter name="cache.adapter.redis" provider="redis://user:[email protected]" />
414+
</framework:pool>
422415
</framework:cache>
423416
</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>
435417
</container>
436418
437419
.. code-block:: php
@@ -441,39 +423,17 @@ case the value needs to be recalculated.
441423
'cache' => [
442424
'pools' => [
443425
'my_cache_pool' => [
444-
'adapter' => 'cache.adapter.psr6',
445-
'provider' => 'app.my_cache_chain_adapter',
446-
],
447-
'cache.my_redis' => [
448-
'adapter' => 'cache.adapter.redis',
449-
'provider' => 'redis://user:[email protected]',
450-
],
451-
'cache.apcu' => [
452-
'adapter' => 'cache.adapter.apcu',
453-
],
454-
'cache.array' => [
455-
'adapter' => 'cache.adapter.array',
426+
'default_lifetime' => 31536000, // One year
427+
'adapters' => [
428+
'cache.adapter.array',
429+
'cache.adapter.apcu',
430+
['name' => 'cache.adapter.redis', 'provider' => 'redis://user:[email protected]'],
431+
],
456432
],
457433
],
458434
],
459435
]);
460436
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-
469-
.. note::
470-
471-
In this configuration the ``my_cache_pool`` pool is using the ``cache.adapter.psr6``
472-
adapter and the ``app.my_cache_chain_adapter`` service as a provider. That is
473-
because ``ChainAdapter`` does not support the ``cache.pool`` tag. So it is decorated
474-
with the ``ProxyAdapter``.
475-
476-
477437
Using Cache Tags
478438
----------------
479439

0 commit comments

Comments
 (0)