Skip to content

Commit

Permalink
feature #4280 [Cookbook][Cache] Added config example for Varnish 4.0 …
Browse files Browse the repository at this point in the history
…(thierrymarianne)

This PR was merged into the 2.3 branch.

Discussion
----------

[Cookbook][Cache] Added config example for Varnish 4.0

| Q             | A
| ------------- | ---
| Doc fix?      | [yes]
| New docs?     | [no]
| Applies to    | [all]
| Fixed tickets | []

After upgrading to `Varnish 4.0`, I've noticed the documentation was not really up-to-date anymore:

 * according to https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#req-not-available-in-vcl-backend-response,

  `beresp` is available in `vcl_backend_response`

 * according to https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#hit-for-pass-objects-are-created-using-beresp-uncacheable,

   `hit_for_pass` objects are created via `beresp.uncacheable`

Would this addition be enough in order to consider the documentation up-to-date in accordance with `Varnish 4.0` upgrading guidelines?

Commits
-------

f3b7394 Added config example for Varnish 4.0
  • Loading branch information
weaverryan committed Oct 28, 2014
2 parents 9a76309 + f3b7394 commit d79c48d
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions cookbook/cache/varnish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,62 @@ Then, optimize Varnish so that it only parses the Response contents when there
is at least one ESI tag by checking the ``Surrogate-Control`` header that
Symfony adds automatically:

.. code-block:: text
.. configuration-block::

sub vcl_fetch {
/*
Check for ESI acknowledgement
and remove Surrogate-Control header
*/
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
.. code-block:: varnish4
// For Varnish >= 3.0
set beresp.do_esi = true;
// For Varnish < 3.0
// esi;
/* (https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#req-not-available-in-vcl-backend-response) */
sub vcl_backend_response {
// Check for ESI acknowledgement and remove Surrogate-Control header
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
/* By default Varnish ignores Pragma: nocache
(https://www.varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html#cache-control)
so in order avoid caching it has to be done explicitly */
if (beresp.http.Pragma ~ "no-cache") {
// https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html#hit-for-pass-objects-are-created-using-beresp-uncacheable
set beresp.uncacheable = true;
set beresp.ttl = 120s;
return (deliver);
}
}
/* By default Varnish ignores Cache-Control: nocache
(https://www.varnish-cache.org/docs/3.0/tutorial/increasing_your_hitrate.html#cache-control),
so in order avoid caching it has to be done explicitly */
if (beresp.http.Pragma ~ "no-cache" ||
beresp.http.Cache-Control ~ "no-cache" ||
beresp.http.Cache-Control ~ "private") {
return (hit_for_pass);
.. code-block:: varnish3
sub vcl_fetch {
// Check for ESI acknowledgement and remove Surrogate-Control header
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
/* By default Varnish ignores Cache-Control: nocache
(https://www.varnish-cache.org/docs/3.0/tutorial/increasing_your_hitrate.html#cache-control),
so in order avoid caching it has to be done explicitly */
if (beresp.http.Pragma ~ "no-cache" ||
beresp.http.Cache-Control ~ "no-cache" ||
beresp.http.Cache-Control ~ "private") {
return (hit_for_pass);
}
}
.. code-block:: varnish2
sub vcl_fetch {
// Check for ESI acknowledgement and remove Surrogate-Control header
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
esi;
}
/* By default Varnish ignores Cache-Control: nocache
so in order avoid caching it has to be done explicitly */
if (beresp.http.Pragma ~ "no-cache" ||
beresp.http.Cache-Control ~ "no-cache" ||
beresp.http.Cache-Control ~ "private") {
return (hit_for_pass);
}
}
}
.. caution::

Expand Down

0 comments on commit d79c48d

Please sign in to comment.