@@ -77,79 +77,35 @@ but it is a great way to start.
7777
7878 For details on setting up Varnish, see :doc: `/http_cache/varnish `.
7979
80- To enable the proxy, first create a caching kernel: :
80+ To enable the proxy for the `` prod `` env, enable the `` framework.http_cache `` setting :
8181
82- // src/CacheKernel.php
83- namespace App;
82+ .. configuration-block ::
8483
85- use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
84+ .. code-block :: yaml
8685
87- class CacheKernel extends HttpCache
88- {
89- }
90-
91- Modify the code of your front controller to wrap the default kernel into the
92- caching kernel:
86+ # config/packages/framework.yaml
87+ when@prod :
88+ framework :
89+ http_cache : true
9390
94- .. code-block :: diff
91+ .. code-block :: php
9592
96- // public/index.php
93+ // config/packages/framework.php
94+ use Symfony\Config\FrameworkConfig;
9795
98- + use App\CacheKernel;
99- use App\Kernel;
100-
101- // ...
102- $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
103- + // Wrap the default Kernel with the CacheKernel one in 'prod' environment
104- + if ('prod' === $kernel->getEnvironment()) {
105- + return new CacheKernel($kernel);
106- + }
107- return $kernel;
96+ return static function (FrameworkConfig $framework) use ($env) {
97+ if ('prod' === $env) {
98+ $framework->httpCache()->enabled(true);
99+ }
100+ };
108101
109-
110- The caching kernel will immediately act as a reverse proxy: caching responses
102+ The kernel will immediately act as a reverse proxy: caching responses
111103from your application and returning them to the client.
112104
113- .. caution ::
114-
115- If you're using the :ref: `framework.http_method_override <configuration-framework-http_method_override >`
116- option to read the HTTP method from a ``_method `` parameter, see the
117- above link for a tweak you need to make.
118-
119- .. tip ::
120-
121- The cache kernel has a special ``getLog() `` method that returns a string
122- representation of what happened in the cache layer. In the development
123- environment, use it to debug and validate your cache strategy::
124-
125- error_log($kernel->getLog());
126-
127- The ``CacheKernel `` object has a sensible default configuration, but it can be
128- finely tuned via a set of options you can set by overriding the
129- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ HttpCache\\ HttpCache::getOptions `
130- method::
131-
132- // src/CacheKernel.php
133- namespace App;
134-
135- use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
136-
137- class CacheKernel extends HttpCache
138- {
139- protected function getOptions(): array
140- {
141- return [
142- 'default_ttl' => 0,
143- // ...
144- ];
145- }
146- }
147-
148- For a full list of the options and their meaning, see the
149- :method: `HttpCache::__construct() documentation <Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache::__construct> `.
105+ The proxy has a sensible default configuration, but it can be
106+ finely tuned via `a set of options<configuration-framework-http_cache> `.
150107
151- When you're in debug mode (the second argument of ``Kernel `` constructor in the
152- front controller is ``true ``), Symfony automatically adds an ``X-Symfony-Cache ``
108+ When in debug mode, Symfony automatically adds an ``X-Symfony-Cache ``
153109header to the response. You can also use the ``trace_level `` config
154110option and set it to either ``none ``, ``short `` or ``full `` to
155111add this information.
0 commit comments