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