Skip to content

[HTTP Cache] typo; improve/simplify code samples; formatting #3350

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 2 commits into from
Dec 26, 2013
Merged
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
39 changes: 21 additions & 18 deletions book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ The ``Cache-Control`` header is unique in that it contains not one, but various
pieces of information about the cacheability of a response. Each piece of
information is separated by a comma:

Cache-Control: private, max-age=0, must-revalidate
.. code-block:: text

Cache-Control: private, max-age=0, must-revalidate

Cache-Control: max-age=3600, must-revalidate
Cache-Control: max-age=3600, must-revalidate

Symfony provides an abstraction around the ``Cache-Control`` header to make
its creation more manageable::
Expand Down Expand Up @@ -662,7 +664,7 @@ exposing a simple and efficient pattern::
// a database or a key-value store for instance)
$article = ...;

// create a Response with a ETag and/or a Last-Modified header
// create a Response with an ETag and/or a Last-Modified header
$response = new Response();
$response->setETag($article->computeETag());
$response->setLastModified($article->getPublishedAt());
Expand All @@ -674,17 +676,17 @@ exposing a simple and efficient pattern::
if ($response->isNotModified($this->getRequest())) {
// return the 304 Response immediately
return $response;
} else {
// do more work here - like retrieving more data
$comments = ...;

// or render a template with the $response you've already started
return $this->render(
'MyBundle:MyController:article.html.twig',
array('article' => $article, 'comments' => $comments),
$response
);
}

// do more work here - like retrieving more data
$comments = ...;

// or render a template with the $response you've already started
return $this->render(
'MyBundle:MyController:article.html.twig',
array('article' => $article, 'comments' => $comments),
$response
);
}

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

.. configuration-block::

Expand Down Expand Up @@ -1058,10 +1061,10 @@ Here is how you can configure the Symfony2 reverse proxy to support the
}

$response = new Response();
if (!$this->getStore()->purge($request->getUri())) {
$response->setStatusCode(404, 'Not purged');
} else {
if ($this->getStore()->purge($request->getUri())) {
$response->setStatusCode(200, 'Purged');
} else {
$response->setStatusCode(404, 'Not purged');
}

return $response;
Expand Down