Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created May 29, 2014 02:39
Show Gist options
  • Save lsegal/efafcab637e99ecee085 to your computer and use it in GitHub Desktop.
Save lsegal/efafcab637e99ecee085 to your computer and use it in GitHub Desktop.
import std;
backend default { .host = "app1.rubydoc.org"; .port = "8080"; }
acl purge {
"localhost";
"app1.rubydoc.org"; // and the backend server
}
sub vcl_recv {
// We don't need no cookies
unset req.http.Cookie;
if (req.url ~ "process=true") {
return (pass); // don't cache process pages
}
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
ban_url("^" + req.http.x-path);
error 200 "Purged.";
}
}
sub vcl_hash {
hash_data(regsub(req.url, "(\?|&)_=.+$", ""));
return (hash);
}
sub vcl_fetch {
// if (beresp.status >= 500) {
// set beresp.saintmode = 10s;
if (beresp.status != 200 || beresp.http.cache-control ~ "max-age=0") {
//set beresp.ttl = 3s;
//set beresp.saintmode = 3s;
return (hit_for_pass); // no cache on non-200s
} else {
// one year cache
set beresp.ttl = 365d;
}
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment