From 83ada059b01c14551d410d29f7967968df5c485f Mon Sep 17 00:00:00 2001 From: Tony Miller Date: Thu, 22 Oct 2020 07:06:34 +1100 Subject: [PATCH] cache public static files from drupal --- templates/presets/drupal.vcl.tmpl | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/templates/presets/drupal.vcl.tmpl b/templates/presets/drupal.vcl.tmpl index dac32fd..e2c19eb 100644 --- a/templates/presets/drupal.vcl.tmpl +++ b/templates/presets/drupal.vcl.tmpl @@ -11,9 +11,10 @@ sub vcl_recv { } # Remove all cookies that Drupal doesn't need to know about. We explicitly - # list the ones that Drupal does need, the SESS and NO_CACHE. If, after - # running this code we find that either of these two cookies remains, we - # will pass as the page cannot be cached. + # list the ones that Drupal does need, the SESS and NO_CACHE. If no cookies + # remain then the page can be cached. + # If some cookies do remain, the response still might be cached by static.vcl + # if the request is for a public static file. if (req.http.Cookie) { {{ $preserved_cookies := (getenv "VARNISH_DRUPAL_PRESERVED_COOKIES" "SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE") }} @@ -37,17 +38,11 @@ sub vcl_recv { # the page. unset req.http.Cookie; } - else { - # If there is any cookies left (a session or NO_CACHE cookie), do not - # cache anything EXCEPT static files. - - {{ $static_files := (getenv "VARNISH_STATIC_FILES" "asc|doc|xls|ppt|csv|svg|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|webp") }} - - if (!((getenv "VARNISH_CACHE_STATIC_FILES") && (req.url ~ "(?i)\.({{ $static_files }})(\?.*)?$"))) { - # Not a static file or VARNISH_CACHE_STATIC_FILES not set. - # Proceed directly to apache, skipping static.vcl processing. - return (pass); - } - } } } + + +sub vcl_backend_response { + # Set the default TTL + set beresp.ttl = {{ getenv "VARNISH_DEFAULT_TTL" "120s" }}; +} \ No newline at end of file