Skip to content

Commit 109159b

Browse files
committed
[HttpCache] Decorate http_cache only in prod env
1 parent 5d49314 commit 109159b

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

http_cache/cache_invalidation.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ Then, register the class as a service that :doc:`decorates </service_container/s
9393
.. code-block:: yaml
9494
9595
# config/services.yaml
96-
services:
97-
App\CacheKernel:
98-
decorates: http_cache
99-
arguments:
100-
- '@kernel'
101-
- '@http_cache.store'
102-
- '@?esi'
96+
when@prod:
97+
services:
98+
App\CacheKernel:
99+
decorates: http_cache
100+
arguments:
101+
- '@kernel'
102+
- '@http_cache.store'
103+
- '@?esi'
103104
104105
.. code-block:: xml
105106
@@ -110,11 +111,15 @@ Then, register the class as a service that :doc:`decorates </service_container/s
110111
xsi:schemaLocation="http://symfony.com/schema/dic/services
111112
https://symfony.com/schema/dic/services/services-1.0.xsd"
112113
>
113-
<service id="App\CacheKernel" decorates="http_cache">
114-
<argument type="service" id="kernel"/>
115-
<argument type="service" id="http_cache.store"/>
116-
<argument type="service" id="esi" on-invalid="null"/>
117-
</service>
114+
<when env="prod">
115+
<services>
116+
<service id="App\CacheKernel" decorates="http_cache">
117+
<argument type="service" id="kernel"/>
118+
<argument type="service" id="http_cache.store"/>
119+
<argument type="service" id="esi" on-invalid="null"/>
120+
</service>
121+
</services>
122+
</when>
118123
</container>
119124
120125
.. code-block:: php
@@ -124,17 +129,18 @@ Then, register the class as a service that :doc:`decorates </service_container/s
124129
125130
use App\CacheKernel;
126131
127-
return function (ContainerConfigurator $containerConfigurator) {
128-
$services = $containerConfigurator->services();
129-
130-
$services->set(CacheKernel::class)
131-
->decorate('http_cache')
132-
->args([
133-
service('kernel'),
134-
service('http_cache.store'),
135-
service('esi')->nullOnInvalid(),
136-
])
137-
;
132+
return function (ContainerConfigurator $containerConfigurator, string $env) {
133+
if ('prod' === $env) {
134+
$containerConfigurator->services()
135+
->set(CacheKernel::class)
136+
->decorate('http_cache')
137+
->args([
138+
service('kernel'),
139+
service('http_cache.store'),
140+
service('esi')->nullOnInvalid(),
141+
])
142+
;
143+
}
138144
};
139145
140146
.. caution::

0 commit comments

Comments
 (0)