Skip to content

Commit 59f5e18

Browse files
committed
minor #8682 Updated http_cache/* articles to Symfony 4 (javiereguiluz, weaverryan)
This PR was merged into the 4.0 branch. Discussion ---------- Updated http_cache/* articles to Symfony 4 I have a question about the old `AppCache` class. I've moved to `src/AppCache.php` under `App` namespace. Is that correct? And also: should we rename it to `Cache` or `KernelCache` or something else? AppCache was great when we had AppKernel ... but now we have just Kernel. Commits ------- 1e75772 Merge branch '4.0' into update_http_cache 664f280 Merge branch '4.0' into update_http_cache d512875 Updated http_cache/* articles to Symfony 4
2 parents c4707d1 + 1e75772 commit 59f5e18

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

http_cache.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ finely tuned via a set of options you can set by overriding the
125125
method::
126126

127127
// src/CacheKernel.php
128+
namespace App;
129+
128130
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
129131

130132
class CacheKernel extends HttpCache
@@ -141,10 +143,9 @@ method::
141143
For a full list of the options and their meaning, see the
142144
:method:`HttpCache::__construct() documentation <Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache::__construct>`.
143145

144-
When you're in debug mode (either because your booting a ``debug`` kernel, like
145-
in ``index.php`` *or* you manually set the ``debug`` option to true), Symfony
146-
automatically adds an ``X-Symfony-Cache`` header to the response. Use this to get
147-
information about cache hits and misses.
146+
When you're in debug mode (the second argument of ``Kernel`` constructor in the
147+
front controller is ``true``), Symfony automatically adds an ``X-Symfony-Cache``
148+
header to the response. Use this to get information about cache hits and misses.
148149

149150
.. _http-cache-symfony-versus-varnish:
150151

@@ -218,7 +219,7 @@ The *easiest* way to cache a response is by caching it for a specific amount of
218219
use Symfony\Component\HttpFoundation\Response;
219220
// ...
220221

221-
public function indexAction()
222+
public function index()
222223
{
223224
// somehow create a Response object, like by rendering a template
224225
$response = $this->render('blog/index.html.twig', []);

http_cache/esi.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ First, to use ESI, be sure to enable it in your application configuration:
6262

6363
.. code-block:: yaml
6464
65-
# app/config/config.yml
65+
# config/packages/framework.yaml
6666
framework:
6767
# ...
6868
esi: { enabled: true }
6969
7070
.. code-block:: xml
7171
72-
<!-- app/config/config.xml -->
72+
<!-- config/packages/framework.xml -->
7373
<?xml version="1.0" encoding="UTF-8" ?>
7474
<container xmlns="http://symfony.com/schema/dic/symfony"
7575
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -87,7 +87,7 @@ First, to use ESI, be sure to enable it in your application configuration:
8787
8888
.. code-block:: php
8989
90-
// app/config/config.php
90+
// config/packages/framework.php
9191
$container->loadFromExtension('framework', array(
9292
// ...
9393
'esi' => array('enabled' => true),
@@ -104,7 +104,7 @@ independent of the rest of the page.
104104
// ...
105105
class DefaultController extends Controller
106106
{
107-
public function aboutAction()
107+
public function about()
108108
{
109109
$response = $this->render('static/about.html.twig');
110110
// set the shared max age - which also marks the response as public
@@ -195,7 +195,7 @@ of the master page.
195195
// ...
196196
class NewsController extends Controller
197197
{
198-
public function latestAction($maxPerPage)
198+
public function latest($maxPerPage)
199199
{
200200
// ...
201201
$response->setSharedMaxAge(60);
@@ -220,14 +220,14 @@ that must be enabled in your configuration:
220220

221221
.. code-block:: yaml
222222
223-
# app/config/config.yml
223+
# config/packages/framework.yaml
224224
framework:
225225
# ...
226226
fragments: { path: /_fragment }
227227
228228
.. code-block:: xml
229229
230-
<!-- app/config/config.xml -->
230+
<!-- config/packages/framework.xml -->
231231
<?xml version="1.0" encoding="UTF-8" ?>
232232
<container xmlns="http://symfony.com/schema/dic/services"
233233
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -245,7 +245,7 @@ that must be enabled in your configuration:
245245
246246
.. code-block:: php
247247
248-
// app/config/config.php
248+
// config/packages/framework.php
249249
$container->loadFromExtension('framework', array(
250250
// ...
251251
'fragments' => array('path' => '/_fragment'),

http_cache/validation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ To see a simple implementation, generate the ETag as the md5 of the content::
6666

6767
class DefaultController extends Controller
6868
{
69-
public function homepageAction(Request $request)
69+
public function homepage(Request $request)
7070
{
7171
$response = $this->render('static/homepage.html.twig');
7272
$response->setEtag(md5($response->getContent()));
@@ -131,7 +131,7 @@ header value::
131131

132132
class ArticleController extends Controller
133133
{
134-
public function showAction(Article $article, Request $request)
134+
public function show(Article $article, Request $request)
135135
{
136136
$author = $article->getAuthor();
137137

@@ -190,7 +190,7 @@ exposing a simple and efficient pattern::
190190

191191
class ArticleController extends Controller
192192
{
193-
public function showAction($articleSlug, Request $request)
193+
public function show($articleSlug, Request $request)
194194
{
195195
// Get the minimum information to compute
196196
// the ETag or the Last-Modified value

0 commit comments

Comments
 (0)