Search code examples
varnishvarnish-vcl

Caching selected URLs with Varnish


Is there a way to provide a static list of URLs to cache? I know that I can put a bunch of 'if' statements in the VCL but I am wondering if there is a more elegant way.


Solution

  • Put them to regular expression

    if (req.url ~ "^/(some/url/1|some/url/2|....|some/urlN)") {
        unset req.http.Cookie;
        return (lookup);
    }
    else {
        return (pass);
    }
    

    or just list with ||

        if (req.url ~ "^/some/url/1"
        || req.url ~ "^/some/url/2
        ...
        || req.url ~ "^/some/urlN"
        ) {
                unset req.http.Cookie;
                return (lookup);
        }