@@ -77,23 +77,29 @@ but is a great way to start.
77
77
78
78
For details on setting up Varnish, see :doc: `/http_cache/varnish `.
79
79
80
- Enabling the proxy is easy: each application comes with a caching kernel (``AppCache ``)
81
- that wraps the default one (``AppKernel ``). The caching Kernel *is * the reverse
82
- proxy.
80
+ To enable the proxy, first create a caching kernel::
83
81
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::
82
+ // src/CacheKernel.php
83
+ <?php
84
+
85
+ use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
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::
86
93
87
94
// public/index.php
88
95
use Symfony\Component\HttpFoundation\Request;
89
96
90
97
// ...
91
- $kernel = new AppKernel('prod', false);
92
- $kernel->loadClassCache();
98
+ $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));
93
99
94
- // add (or uncomment) this new line!
95
- // wrap the default Kernel with the AppCache one
96
- $kernel = new AppCache ($kernel);
100
+ // Add this line.
101
+ // wrap the default Kernel with the CacheKernel one
102
+ $kernel = new CacheKernel ($kernel);
97
103
98
104
$request = Request::createFromGlobals();
99
105
// ...
@@ -115,15 +121,15 @@ from your application and returning them to the client.
115
121
116
122
error_log($kernel->getLog());
117
123
118
- The ``AppCache `` object has a sensible default configuration, but it can be
124
+ The ``CacheKernel `` object has a sensible default configuration, but it can be
119
125
finely tuned via a set of options you can set by overriding the
120
126
:method: `Symfony\\ Bundle\\ FrameworkBundle\\ HttpCache\\ HttpCache::getOptions `
121
127
method::
122
128
123
- // app/AppCache .php
129
+ // src/CacheKernel .php
124
130
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
125
131
126
- class AppCache extends HttpCache
132
+ class CacheKernel extends HttpCache
127
133
{
128
134
protected function getOptions()
129
135
{
@@ -150,7 +156,7 @@ information about cache hits and misses.
150
156
website or when you deploy your website to a shared host where you cannot
151
157
install anything beyond PHP code. But being written in PHP, it cannot
152
158
be as fast as a proxy written in C.
153
-
159
+
154
160
Fortunately, since all reverse proxies are effectively the same, you should
155
161
be able to switch to something more robust - like Varnish - without any problems.
156
162
See :doc: `How to use Varnish </http_cache/varnish >`
@@ -192,7 +198,7 @@ These four headers are used to help cache your responses via *two* different mod
192
198
193
199
All of the HTTP headers you'll read about are *not * invented by Symfony! They're
194
200
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
201
+ into HTTP Caching, check out the documents `RFC 7234 - Caching `_ and
196
202
`RFC 7232 - Conditional Requests `_.
197
203
198
204
As a web developer, you are strongly urged to read the specification. Its
0 commit comments