From f958391bb74c9a63fc2050b85e401e195f36914b Mon Sep 17 00:00:00 2001 From: Gonzalo Vilaseca Date: Wed, 11 Jun 2014 15:45:24 +0100 Subject: [PATCH 1/3] Varnish only takes into account max-age Varnish only takes into account max-age, Symfony by default returns Cache-Control: no-cache so Varnish caches it anyway. You need to specify: ``` if (beresp.http.Pragma ~ "no-cache" || beresp.http.Cache-Control ~ "no-cache" || beresp.http.Cache-Control ~ "private") { return (hit_for_pass); } ``` In order to avoid Varnish from caching content. --- cookbook/cache/varnish.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index 48eb43c2592..477809ca74b 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -57,6 +57,12 @@ Symfony2 adds automatically: // For Varnish < 3.0 // esi; } + /* Do not cache if no-cache is found in headers */ + if (beresp.http.Pragma ~ "no-cache" || + beresp.http.Cache-Control ~ "no-cache" || + beresp.http.Cache-Control ~ "private") { + return (hit_for_pass); + } } .. caution:: From 8848549099d6fbb046f248a347b99324bd4f72ed Mon Sep 17 00:00:00 2001 From: Gonzalo Vilaseca Date: Wed, 11 Jun 2014 17:12:59 +0100 Subject: [PATCH 2/3] Update varnish.rst --- cookbook/cache/varnish.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index 477809ca74b..6794793e83d 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -57,7 +57,8 @@ Symfony2 adds automatically: // For Varnish < 3.0 // esi; } - /* Do not cache if no-cache is found in headers */ + /* 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") { From 466bd6abca9b6fadf2bf4740add1a126373f8b1a Mon Sep 17 00:00:00 2001 From: Gonzalo Vilaseca Date: Wed, 11 Jun 2014 18:43:31 +0100 Subject: [PATCH 3/3] Update varnish.rst --- cookbook/cache/varnish.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index 6794793e83d..da06add99f1 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -57,7 +57,8 @@ Symfony2 adds automatically: // For Varnish < 3.0 // esi; } - /* By default Varnish ignores Cache-Control: nocache (https://www.varnish-cache.org/docs/3.0/tutorial/increasing_your_hitrate.html#cache-control), + /* 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" ||