@@ -77,82 +77,39 @@ but it is a great way to start.
77
77
78
78
For details on setting up Varnish, see :doc: `/http_cache/varnish `.
79
79
80
- To enable the proxy, first create a caching kernel::
80
+ Use the ``framework.http_cache `` option to enable the proxy for the
81
+ :ref: `prod environment <configuration-environments >`:
81
82
82
- // src/CacheKernel.php
83
- namespace App;
83
+ .. configuration-block ::
84
84
85
- use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
85
+ .. code-block :: yaml
86
86
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:
87
+ # config/packages/framework.yaml
88
+ when@prod :
89
+ framework :
90
+ http_cache : true
93
91
94
- .. code-block :: diff
92
+ .. code-block :: php
95
93
96
- // public/index.php
94
+ // config/packages/framework.php
95
+ use Symfony\Config\FrameworkConfig;
97
96
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;
97
+ return static function (FrameworkConfig $framework) use ($env) {
98
+ if ('prod' === $env) {
99
+ $framework->httpCache()->enabled(true);
100
+ }
101
+ };
108
102
109
-
110
- The caching kernel will immediately act as a reverse proxy: caching responses
103
+ The kernel will immediately act as a reverse proxy: caching responses
111
104
from your application and returning them to the client.
112
105
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> `.
106
+ The proxy has a sensible default configuration, but it can be
107
+ finely tuned via `a set of options <configuration-framework-http_cache> `.
150
108
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 ``
153
- header to the response. You can also use the ``trace_level `` config
154
- option and set it to either ``none ``, ``short `` or ``full `` to
155
- add this information.
109
+ When in :ref: `debug mode <debug-mode >`, Symfony automatically adds an
110
+ ``X-Symfony-Cache `` header to the response. You can also use the ``trace_level ``
111
+ config option and set it to either ``none ``, ``short `` or ``full `` to add this
1E0A
112
+ information.
156
113
157
114
``short `` will add the information for the main request only.
158
115
It's written in a concise way that makes it easy to record the
0 commit comments