Problem with varnish and caching

Anup Shukla anup at iamcool.net
Wed Jul 4 06:07:46 CEST 2007


Manuel Amador (Rudd-O) wrote:
> The optimum behaviour would be Varnish caching static files
> (img,css,jpg,png, based on response HTTP headers) and not caching
> dynamic ones.  But as it currently stands, Varnish configuration
> language doesn't allow caching to be controlled based on the response
> headers, only on the request ones.  Squid, however, does.
>
>   

I had a similar situation.
In my case the site is 100% php, so in effect anything that comes out 
with Content-Type text/html is php generated and given the nature of the 
site, its not cacheable.

I have also put below my VCL configuration which works fine for me.
Its not much of a high quality configuration, but works for me.

Suggestion, as always, are welcome :)

sub vcl_recv {
        if (req.request == "GET" && req.http.cookie) {
                lookup;
        }
}

sub vcl_fetch {
        if (!obj.valid) {
                error;
        }
        if (!obj.cacheable) {
                pass;
        }
        if (resp.http.Content-Type ~ "text/html") {
                pass;
        }
        if (resp.http.Set-Cookie) {
                insert;
        }
        insert;
}

Hope this helps.

Regards
A.S



More information about the varnish-misc mailing list