Skip to content

Instantly share code, notes, and snippets.

@initcron
Created June 14, 2013 12:16
Show Gist options
  • Save initcron/5781371 to your computer and use it in GitHub Desktop.
Save initcron/5781371 to your computer and use it in GitHub Desktop.
varnish cache ttl settings
sub vcl_fetch {
set beresp.grace = 300s;
if (beresp.http.Set-Cookie) {
return(deliver);
}
if (req.url ~ "\.css$") {
set beresp.ttl = 120s;
}
if (req.url ~ "\.ajax$") {
set beresp.ttl = 20s;
}
if (req.url ~ "\.js$") {
set beresp.ttl = 120s;
}
if (req.url ~ "\.html$") {
set beresp.ttl = 180s;
}
if (req.url ~ "\.xml$") {
set beresp.ttl = 180s;
}
if (req.url ~ "\.htm$") {
set beresp.ttl = 180s;
}
}
# if (beresp.ttl < 10s) {
# /* If a ttl is set to 0 or less as per default TTL rules, so will obj.cacheable. You can overwrite
# * this, and you should if you are chaning from not caching to caching.
# */
# set beresp.ttl = 300s;
# }
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120 s;
return (hit_for_pass);
}
if (req.url ~ "\.php$") {
set beresp.ttl = 0s;
}
if (req.url ~ "\.(swf|flv|mp4)") {
set beresp.ttl = 0s;
}
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment