Skip to content

Instantly share code, notes, and snippets.

@section-io-gists
Created October 12, 2017 06:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save section-io-gists/bad6cfc58a4db2cb461c3cc53a565cc3 to your computer and use it in GitHub Desktop.
Save section-io-gists/bad6cfc58a4db2cb461c3cc53a565cc3 to your computer and use it in GitHub Desktop.
sub vcl_recv {
if (req.method != "GET" && req.method != "HEAD" && req.method != "PURGE") {
return (pass);
}
// Rest of vcl_recv code
return(hash);
}
sub vcl_backend_response {
if (bereq.method != "GET" && bereq.method != "HEAD" && bereq.method != "PURGE") {
set beresp.uncacheable = true;
set beresp.ttl = 120s;
return (deliver);
}
if (beresp.http.Content-Type ~ "text/html" && beresp.status < 400) {
if (bereq.http.Cookie !~ "ASP.NET_SessionId" && bereq.url !~ "(/[Cc]art|/[Cc]heckout|/[Aa]dmin|/[Ll]ogin|/[Aa]ccount)") {
unset beresp.http.Set-Cookie;
set beresp.ttl = 6h;
set beresp.grace = 12h;
} else {
set beresp.uncacheable = true;
set beresp.ttl = 120s;
}
return (deliver);
}
}
sub vcl_hash {
if (req.http.Cookie !~ "ASP.NET_SessionId" && req.url !~ "(/[Cc]art|/[Cc]heckout|/[Aa]dmin|/[Ll]ogin|/[Aa]ccount)") {
hash_data("no_unique_cookie");
} else {
hash_data("has_unique_cookie");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment