Search code examples
varnishvarnish-vcl

Varnish 4 Cache does not cache dynamic page


It is possible cache of dynamic pages, especially the home page?

For plan to reduce access to the database .

I can do static file cache. perfect.

Response headers

Accept-Ranges:bytes

Age:0

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Connection:keep-alive

Content-Type:text/html; charset=utf-8

Date:Tue, 09 Dec 2014 17:07:13 GMT

Expires:Thu, 19 Nov 1981 08:52:00 GMT

Pragma:no-cache

Transfer-Encoding:chunked

Via:1.1 varnish-v4

x-Cache:uncached

X-Varnish:295421

File default vcl: http://notepad.cc/vaokodde9


Solution

  • Your backend is screamming it doesn't want anyone to cache the page:

    Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Expires:Thu, 19 Nov 1981 08:52:00 GMT
    Pragma:no-cache
    

    It's setting all the Cache-Control headers to disallow cache, it's setting an Expires header in the past (way back), and a Pragma: no-cache. You either have to fix the backend to send headers that allow caching, or if you are sure that you won't break anything start to workaround this headers in vcl.

    I would choose the first option, and work the Cookies issue later.