X-VC-TTL for static files
X-VC-TTL for static files

--- a/varnish-conf/default.vcl
+++ b/varnish-conf/default.vcl
@@ -101,7 +101,9 @@
     }
 
     # overwrite ttl with X-VC-TTL
-    set beresp.ttl = std.duration(beresp.http.X-VC-TTL + "s", 0s);
+    if (beresp.http.X-VC-TTL) {
+        set beresp.ttl = std.duration(beresp.http.X-VC-TTL + "s", 0s);
+    }
 
     # catch obvious reasons we can't cache
     if (beresp.http.Set-Cookie) {

--- a/varnish-conf/lib/purge.vcl
+++ b/varnish-conf/lib/purge.vcl
@@ -86,8 +86,9 @@
     if (resp.http.X-VC-Debug ~ "true") {
         set resp.http.X-VC-Hash = req.url+"#"+req.http.host;
     } else {
+        unset resp.http.X-VC-Enabled;
+        unset resp.http.X-VC-Cache;
         unset resp.http.X-VC-Debug;
-        unset resp.http.X-VC-Enabled;
         unset resp.http.X-VC-Cacheable;
         unset resp.http.X-VC-Purge-Key-Auth;
         unset resp.http.X-VC-TTL;

--- a/varnish-conf/lib/static.vcl
+++ b/varnish-conf/lib/static.vcl
@@ -1,26 +1,27 @@
 # static.vcl -- Static File Caching for Varnish
 
 sub vcl_recv {
-	if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)(\?.*)?$") {
-		# disable this if you want
-		if (req.url ~ "nocache") {
-			return(pass);
-		}
-		set req.url = regsub(req.url, "\?.*$", "");
-		unset req.http.Cookie;
-		set req.grace = 2m;
-		return(lookup);
-	}
+    if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)(\?.*)?$") {
+        # disable this if you want
+        if (req.url ~ "nocache") {
+            return(pass);
+        }
+        set req.url = regsub(req.url, "\?.*$", "");
+        # unset cookie only if no http auth
+        if (!req.http.Authorization) {
+            unset req.http.Cookie;
+        }
+        set req.grace = 2m;
+        return(lookup);
+    }
 }
 
 sub vcl_fetch {
-	if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
-		# unset cookie only if no http auth is requested
-		if (!req.http.Authorization) {
-			unset beresp.http.set-cookie;
-		}
-		set beresp.ttl = 24h;
-		set beresp.grace = 2m;
-	}
+    if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
+        # overwrite ttl with X-VC-TTL
+        set beresp.http.X-VC-TTL = "24";
+        set beresp.ttl = std.duration(beresp.http.X-VC-TTL + "h", 0s);
+        set beresp.grace = 2m;
+    }
 }
 

comments