Skip to content

Commit

Permalink
allow static public files to be cached on drupal sites
Browse files Browse the repository at this point in the history
cache public static files from drupal
  • Loading branch information
drasgardian committed Mar 8, 2021
1 parent 960b869 commit eed535a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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,10 +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 the page. Pass it on to Apache directly.
return (pass);
}
}
}


sub vcl_backend_response {
# Set the default TTL
set beresp.ttl = {{ getenv "VARNISH_DEFAULT_TTL" "120s" }};
}

0 comments on commit eed535a

Please sign in to comment.