Skip to content

Commit 8586f39

Browse files
committed
Merge pull request symfony#3350 from bicpi/some_improvements
[HTTP Cache] typo; improve/simplify code samples; formatting
2 parents f0b3e64 + fe925bc commit 8586f39

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

book/http_cache.rst

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ The ``Cache-Control`` header is unique in that it contains not one, but various
301301
pieces of information about the cacheability of a response. Each piece of
302302
information is separated by a comma:
303303

304-
Cache-Control: private, max-age=0, must-revalidate
304+
.. code-block:: text
305+
306+
Cache-Control: private, max-age=0, must-revalidate
305307
306-
Cache-Control: max-age=3600, must-revalidate
308+
Cache-Control: max-age=3600, must-revalidate
307309
308310
Symfony provides an abstraction around the ``Cache-Control`` header to make
309311
its creation more manageable::
@@ -667,7 +669,7 @@ exposing a simple and efficient pattern::
667669
// a database or a key-value store for instance)
668670
$article = ...;
669671

670-
// create a Response with a ETag and/or a Last-Modified header
672+
// create a Response with an ETag and/or a Last-Modified header
671673
$response = new Response();
672674
$response->setETag($article->computeETag());
673675
$response->setLastModified($article->getPublishedAt());
@@ -679,17 +681,17 @@ exposing a simple and efficient pattern::
679681
if ($response->isNotModified($request)) {
680682
// return the 304 Response immediately
681683
return $response;
682-
} else {
683-
// do more work here - like retrieving more data
684-
$comments = ...;
685-
686-
// or render a template with the $response you've already started
687-
return $this->render(
688-
'MyBundle:MyController:article.html.twig',
689-
array('article' => $article, 'comments' => $comments),
690-
$response
691-
);
692684
}
685+
686+
// do more work here - like retrieving more data
687+
$comments = ...;
688+
689+
// or render a template with the $response you've already started
690+
return $this->render(
691+
'MyBundle:MyController:article.html.twig',
692+
array('article' => $article, 'comments' => $comments),
693+
$response
694+
);
693695
}
694696

695697
When the ``Response`` is not modified, the ``isNotModified()`` automatically sets
@@ -956,8 +958,9 @@ component cache will only last for 60 seconds.
956958
When using a controller reference, the ESI tag should reference the embedded
957959
action as an accessible URL so the gateway cache can fetch it independently of
958960
the rest of the page. Symfony2 takes care of generating a unique URL for any
959-
controller reference and it is able to route them properly thanks to a
960-
listener that must be enabled in your configuration:
961+
controller reference and it is able to route them properly thanks to the
962+
:class:`Symfony\\Component\\HttpKernel\\EventListener\\FragmentListener`
963+
that must be enabled in your configuration:
961964

962965
.. configuration-block::
963966

@@ -1063,10 +1066,10 @@ Here is how you can configure the Symfony2 reverse proxy to support the
10631066
}
10641067

10651068
$response = new Response();
1066-
if (!$this->getStore()->purge($request->getUri())) {
1067-
$response->setStatusCode(404, 'Not purged');
1068-
} else {
1069+
if ($this->getStore()->purge($request->getUri())) {
10691070
$response->setStatusCode(200, 'Purged');
1071+
} else {
1072+
$response->setStatusCode(404, 'Not purged');
10701073
}
10711074

10721075
return $response;

0 commit comments

Comments
 (0)