Skip to content

Commit 865d565

Browse files
committed
Update HttpCache kernel documentation for Symfony 4
1 parent 4d5ebc4 commit 865d565

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

configuration/front_controllers_and_kernel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ to `decorate`_ the kernel with additional features. Examples include:
4444

4545
* Configuring the autoloader or adding additional autoloading mechanisms;
4646
* Adding HTTP level caching by wrapping the kernel with an instance of
47-
:ref:`AppCache <symfony-gateway-cache>`;
47+
:ref:`HttpCache <symfony-gateway-cache>`;
4848
* Enabling the :doc:`Debug Component </components/debug>`.
4949

5050
The front controller can be chosen by requesting URLs like:

http_cache.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,29 @@ but is a great way to start.
7777

7878
For details on setting up Varnish, see :doc:`/http_cache/varnish`.
7979

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::
8381

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::
8693

8794
// public/index.php
8895
use Symfony\Component\HttpFoundation\Request;
8996

9097
// ...
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')));
9399

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);
97103

98104
$request = Request::createFromGlobals();
99105
// ...
@@ -115,15 +121,15 @@ from your application and returning them to the client.
115121

116122
error_log($kernel->getLog());
117123

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
119125
finely tuned via a set of options you can set by overriding the
120126
:method:`Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache::getOptions`
121127
method::
122128

123-
// app/AppCache.php
129+
// src/CacheKernel.php
124130
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
125131

126-
class AppCache extends HttpCache
132+
class CacheKernel extends HttpCache
127133
{
128134
protected function getOptions()
129135
{
@@ -150,7 +156,7 @@ information about cache hits and misses.
150156
website or when you deploy your website to a shared host where you cannot
151157
install anything beyond PHP code. But being written in PHP, it cannot
152158
be as fast as a proxy written in C.
153-
159+
154160
Fortunately, since all reverse proxies are effectively the same, you should
155161
be able to switch to something more robust - like Varnish - without any problems.
156162
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
192198

193199
All of the HTTP headers you'll read about are *not* invented by Symfony! They're
194200
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
196202
`RFC 7232 - Conditional Requests`_.
197203

198204
As a web developer, you are strongly urged to read the specification. Its

http_cache/cache_invalidation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ the word "PURGE" is a convention, technically this can be any string) instead
4747
of ``GET`` and make the cache proxy detect this and remove the data from the
4848
cache instead of going to the application to get a response.
4949

50-
Here is how you can configure the Symfony reverse proxy to support the
51-
``PURGE`` HTTP method::
50+
Here is how you can configure the Symfony reverse proxy (See :doc:`/http_cache`)
51+
to support the ``PURGE`` HTTP method::
5252

53-
// app/AppCache.php
53+
// src/CacheKernel.php
5454

5555
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
5656
use Symfony\Component\HttpFoundation\Request;
5757
use Symfony\Component\HttpFoundation\Response;
5858
// ...
5959

60-
class AppCache extends HttpCache
60+
class CacheKernel extends HttpCache
6161
{
6262
protected function invalidate(Request $request, $catch = false)
6363
{

reference/configuration/framework.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ named ``kernel.http_method_override``.
173173

174174
.. caution::
175175

176-
If you're using the :ref:`AppCache Reverse Proxy <symfony2-reverse-proxy>`
176+
If you're using the :ref:`HttpCache Reverse Proxy <symfony2-reverse-proxy>`
177177
with this option, the kernel will ignore the ``_method`` parameter,
178178
which could lead to errors.
179179

180180
To fix this, invoke the ``enableHttpMethodParameterOverride()`` method
181181
before creating the ``Request`` object::
182182

183-
// web/app.php
183+
// public/index.php
184184

185185
// ...
186-
$kernel = new AppCache($kernel);
186+
$kernel = new CacheKernel($kernel);
187187

188188
Request::enableHttpMethodParameterOverride(); // <-- add this line
189189
$request = Request::createFromGlobals();

0 commit comments

Comments
 (0)