Skip to content

[Cache] Make sure the chain cache configuration works #11813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,22 @@ case the value needs to be recalculated.
cache:
pools:
my_cache_pool:
adapter: app.my_cache_chain_adapter
adapter: cache.adapter.psr6
provider: app.my_cache_chain_adapter
cache.my_redis:
adapter: cache.adapter.redis
provider: 'redis://user:password@example.com'
cache.apcu:
adapter: cache.adapter.apcu
cache.array:
adapter: cache.adapter.array


services:
app.my_cache_chain_adapter:
class: Symfony\Component\Cache\Adapter\ChainAdapter
arguments:
- ['cache.adapter.array', 'cache.my_redis', 'cache.adapter.file']
- ['@cache.array', '@cache.apcu', '@cache.my_redis']
- 31536000 # One year

.. code-block:: xml
Expand All @@ -436,18 +442,20 @@ case the value needs to be recalculated.
https://symfony.com/schema/dic/services/services-1.0.xsd">

<framework:config>
<framework:cache default_memcached_provider="memcached://localhost">
<framework:pool name="my_cache_pool" adapter="app.my_cache_chain_adapter"/>
<framework:cache>
<framework:pool name="my_cache_pool" adapter="cache.adapter.psr6" provider="app.my_cache_chain_adapter"/>
<framework:pool name="cache.my_redis" adapter="cache.adapter.redis" provider="redis://user:password@example.com"/>
<framework:pool name="cache.apcu" adapter="cache.adapter.apcu"/>
<framework:pool name="cache.array" adapter="cache.adapter.array"/>
</framework:cache>
</framework:config>

<services>
<service id="app.my_cache_chain_adapter" class="Symfony\Component\Cache\Adapter\ChainAdapter">
<argument type="collection">
<argument type="service" value="cache.adapter.array"/>
<argument type="service" value="cache.array"/>
<argument type="service" value="cache.apcu"/>
<argument type="service" value="cache.my_redis"/>
<argument type="service" value="cache.adapter.file"/>
</argument>
<argument>31536000</argument>
</service>
Expand All @@ -461,28 +469,37 @@ case the value needs to be recalculated.
'cache' => [
'pools' => [
'my_cache_pool' => [
'adapter' => 'app.my_cache_chain_adapter',
'adapter' => 'cache.adapter.psr6',
'provider' => 'app.my_cache_chain_adapter',
],
'cache.my_redis' => [
'adapter' => 'cache.adapter.redis',
'provider' => 'redis://user:password@example.com',
],
'cache.apcu' => [
'adapter' => 'cache.adapter.apcu',
],
'cache.array' => [
'adapter' => 'cache.adapter.array',
],
],
],
]);

$container->getDefinition('app.my_cache_chain_adapter', \Symfony\Component\Cache\Adapter\ChainAdapter::class)
->addArgument([
new Reference('cache.adapter.array'),
new Reference('cache.array'),
new Reference('cache.apcu'),
new Reference('cache.my_redis'),
new Reference('cache.adapter.file'),
])
->addArgument(31536000);

.. note::

In this configuration there is a ``cache.my_redis`` pool that is used as an
adapter in the ``app.my_cache_chain_adapter``
In this configuration the ``my_cache_pool`` pool is using the ``cache.adapter.psr6``
adapter and the ``app.my_cache_chain_adapter`` service as a provider. That is
because ``ChainAdapter`` does not support the ``cache.pool`` tag. So it is decorated
with the ``ProxyAdapter``.


Clearing the Cache
Expand Down