Skip to content

Updated http_cache/* articles to Symfony 4 #8682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ finely tuned via a set of options you can set by overriding the
method::

// src/CacheKernel.php
namespace App;

use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;

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

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

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

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

public function indexAction()
public function index()
{
// somehow create a Response object, like by rendering a template
$response = $this->render('blog/index.html.twig', []);
Expand Down
16 changes: 8 additions & 8 deletions http_cache/esi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ First, to use ESI, be sure to enable it in your application configuration:

.. code-block:: yaml

# app/config/config.yml
# config/packages/framework.yaml
framework:
# ...
esi: { enabled: true }

.. code-block:: xml

<!-- app/config/config.xml -->
<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/symfony"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -87,7 +87,7 @@ First, to use ESI, be sure to enable it in your application configuration:

.. code-block:: php

// app/config/config.php
// config/packages/framework.php
$container->loadFromExtension('framework', array(
// ...
'esi' => array('enabled' => true),
Expand All @@ -104,7 +104,7 @@ independent of the rest of the page.
// ...
class DefaultController extends Controller
{
public function aboutAction()
public function about()
{
$response = $this->render('static/about.html.twig');
// set the shared max age - which also marks the response as public
Expand Down Expand Up @@ -195,7 +195,7 @@ of the master page.
// ...
class NewsController extends Controller
{
public function latestAction($maxPerPage)
public function latest($maxPerPage)
{
// ...
$response->setSharedMaxAge(60);
Expand All @@ -220,14 +220,14 @@ that must be enabled in your configuration:

.. code-block:: yaml

# app/config/config.yml
# config/packages/framework.yaml
framework:
# ...
fragments: { path: /_fragment }

.. code-block:: xml

<!-- app/config/config.xml -->
<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -245,7 +245,7 @@ that must be enabled in your configuration:

.. code-block:: php

// app/config/config.php
// config/packages/framework.php
$container->loadFromExtension('framework', array(
// ...
'fragments' => array('path' => '/_fragment'),
Expand Down
6 changes: 3 additions & 3 deletions http_cache/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ To see a simple implementation, generate the ETag as the md5 of the content::

class DefaultController extends Controller
{
public function homepageAction(Request $request)
public function homepage(Request $request)
{
$response = $this->render('static/homepage.html.twig');
$response->setEtag(md5($response->getContent()));
Expand Down Expand Up @@ -131,7 +131,7 @@ header value::

class ArticleController extends Controller
{
public function showAction(Article $article, Request $request)
public function show(Article $article, Request $request)
{
$author = $article->getAuthor();

Expand Down Expand Up @@ -190,7 +190,7 @@ exposing a simple and efficient pattern::

class ArticleController extends Controller
{
public function showAction($articleSlug, Request $request)
public function show($articleSlug, Request $request)
{
// Get the minimum information to compute
// the ETag or the Last-Modified value
Expand Down