I distribute a PHP script and recently a lot of people are having trouble with varnish cache on shared hosting accounts.
This is the code at the top of the PHP script. However I still get "Varnish: HIT" in response headers (and the script doesn't work correctly).
header('Pragma: no-cache');
header('Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate, proxy-revalidate');
header('Expires: Tue, 04 Sep 2012 05:32:29 GMT');
One hosting provider said it was impossible to disable varnish from within a PHP script, even by setting the cache headers like above. This seems .. well .. silly? But seems to match my experience.
So is there a way to disable/skip varnish from within PHP? Or does varnish (by default) just ignore these cache headers set by PHP?
Thanks Jens-André Koch - I'll include varnish instructions along with the PHP script to make it ignore no-cache responses:
sub vcl_fetch {
if (beresp.http.cache-control ~ "(no-cache|private)" ||
beresp.http.pragma ~ "no-cache") {
set beresp.ttl = 0s;
}
}