@@ -81,18 +81,15 @@ Enabling the proxy is easy: each application comes with a caching kernel (``AppC
81
81
that wraps the default one (``AppKernel ``). The caching Kernel *is * the reverse
82
82
proxy.
83
83
84
- To enable caching, modify the code of your front controller. You can also make these
85
- changes to ``index.php `` to add caching to the ``dev `` environment::
84
+ To enable caching, modify the code of your ``index.php `` front controller::
86
85
87
86
// public/index.php
88
87
use Symfony\Component\HttpFoundation\Request;
89
88
90
89
// ...
91
- $kernel = new AppKernel('prod', false);
92
- $kernel->loadClassCache();
90
+ $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? false);
93
91
94
- // add (or uncomment) this new line!
95
- // wrap the default Kernel with the AppCache one
92
+ // add (or uncomment) this line to wrap the default Kernel with the AppCache one
96
93
$kernel = new AppCache($kernel);
97
94
98
95
$request = Request::createFromGlobals();
@@ -120,7 +117,9 @@ finely tuned via a set of options you can set by overriding the
120
117
:method: `Symfony\\ Bundle\\ FrameworkBundle\\ HttpCache\\ HttpCache::getOptions `
121
118
method::
122
119
123
- // app/AppCache.php
120
+ // src/AppCache.php
121
+ namespace App;
122
+
124
123
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
125
124
126
125
class AppCache extends HttpCache
@@ -137,10 +136,9 @@ method::
137
136
For a full list of the options and their meaning, see the
138
137
:method: `HttpCache::__construct() documentation <Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache::__construct> `.
139
138
140
- When you're in debug mode (either because your booting a ``debug `` kernel, like
141
- in ``index.php `` *or * you manually set the ``debug `` option to true), Symfony
142
- automatically adds an ``X-Symfony-Cache `` header to the response. Use this to get
143
- information about cache hits and misses.
139
+ When you're in debug mode (the second argument of ``Kernel `` constructor in the
140
+ front controller is ``true ``), Symfony automatically adds an ``X-Symfony-Cache ``
141
+ header to the response. Use this to get information about cache hits and misses.
144
142
145
143
.. _http-cache-symfony-versus-varnish :
146
144
@@ -150,7 +148,7 @@ information about cache hits and misses.
150
148
website or when you deploy your website to a shared host where you cannot
151
149
install anything beyond PHP code. But being written in PHP, it cannot
152
150
be as fast as a proxy written in C.
153
-
151
+
154
152
Fortunately, since all reverse proxies are effectively the same, you should
155
153
be able to switch to something more robust - like Varnish - without any problems.
156
154
See :doc: `How to use Varnish </http_cache/varnish >`
@@ -192,7 +190,7 @@ These four headers are used to help cache your responses via *two* different mod
192
190
193
191
All of the HTTP headers you'll read about are *not * invented by Symfony! They're
194
192
part of an HTTP specification that's used by sites all over the web. To dig deeper
195
- into HTTP Caching, check out the documents `RFC 7234 - Caching `_ and
193
+ into HTTP Caching, check out the documents `RFC 7234 - Caching `_ and
196
194
`RFC 7232 - Conditional Requests `_.
197
195
198
196
As a web developer, you are strongly urged to read the specification. Its
@@ -214,7 +212,7 @@ The *easiest* way to cache a response is by caching it for a specific amount of
214
212
use Symfony\Component\HttpFoundation\Response;
215
213
// ...
216
214
217
- public function indexAction ()
215
+ public function index ()
218
216
{
219
217
// somehow create a Response object, like by rendering a template
220
218
$response = $this->render('blog/index.html.twig', []);
0 commit comments