Skip to content

Commit

Permalink
cache public static files from drupal
Browse files Browse the repository at this point in the history
  • Loading branch information
drasgardian committed Oct 21, 2020
1 parent 9113980 commit 83ada05
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions templates/presets/drupal.vcl.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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") }}

Expand All @@ -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" }};
}

0 comments on commit 83ada05

Please sign in to comment.