Home About News Products Blog

Varnish - How to cache everything

htmlcaching
caching
varnish
vcl

#1

User has asked the following

I’m trying to set up a VCL that caches everything. I’ve removed all the headers I can think of. I’ve removed cookies. Still not caching. Is there a sample somewhere of a ‘cache everything’ strategy?

I have the following in sub vcl_recv

if (req.method != "GET" && req.method != "HEAD" && req.method != "PURGE") {
    return (pass);
}

# Goodbye all cookies!
unset req.http.Cookie;
unset req.http.Set-Cookie;
unset req.http.Cache-Control;
unset req.http.Pragma;

return(hash);

In this case it is likely that the origin is not sending the correct Cache-Control header for Varnish to set TTL on a response from origin to cache assets. It would be marking these assets responses as uncacheable. So even though the correct logic in vcl_recv looks up the request in the cache, nothing has being stored in there.

If this is the case, you can either fix the header at the origin, or manually set cache times in vcl_backend_response.
Here is example code of caching everything https://gist.github.com/section-io-gists/56391f3af9dff65dda36