1- # VCL version 7 .0 is not supported so it should be 4.0 even though actually used Varnish version is 7
1+ # VCL version 5 .0 is not supported so it should be 4.0 even though actually used Varnish version is 7
22vcl 4.0 ;
33
44import std;
@@ -81,21 +81,6 @@ sub vcl_recv {
8181 # collect all cookies
8282 std.collect (req.http.Cookie );
8383
84- # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
85- if (req.http.Accept-Encoding ) {
86- if (req.url ~ "\. (jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$" ) {
87- # No point in compressing these
88- unset req.http.Accept-Encoding ;
89- } elsif (req.http.Accept-Encoding ~ "gzip" ) {
90- set req.http.Accept-Encoding = "gzip" ;
91- } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE" ) {
92- set req.http.Accept-Encoding = "deflate" ;
93- } else {
94- # unknown algorithm
95- unset req.http.Accept-Encoding ;
96- }
97- }
98-
9984 # Remove all marketing get parameters to minimize the cache objects
10085 if (req.url ~ "(\? |&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=" ) {
10186 set req.url = regsuball (req.url , "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?" , "" );
@@ -173,9 +158,7 @@ sub vcl_backend_response {
173158 }
174159
175160 # cache only successfully responses and 404s that are not marked as private
176- if (beresp.status != 200 &&
177- beresp.status != 404 &&
178- beresp.http.Cache-Control ~ "private" ) {
161+ if ((beresp.status != 200 && beresp.status != 404 ) || beresp.http.Cache-Control ~ "private" ) {
179162 set beresp.uncacheable = true ;
180163 set beresp.ttl = 86400s ;
181164 return (deliver );
@@ -198,28 +181,30 @@ sub vcl_backend_response {
198181 unset beresp.http.set-cookie ;
199182 }
200183
201- # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
202- if (beresp.ttl <= 0s ||
203- beresp.http.Surrogate-control ~ "no-store" ||
204- (! beresp.http.Surrogate-Control &&
205- beresp.http.Cache-Control ~ "no-cache|no-store" ) ||
206- beresp.http.Vary == "*" ) {
184+ # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
185+ if (beresp.ttl <= 0s ||
186+ beresp.http.Surrogate-control ~ "no-store" ||
187+ (! beresp.http.Surrogate-Control &&
188+ beresp.http.Cache-Control ~ "no-cache|no-store" ) ||
189+ beresp.http.Vary == "*" ) {
207190 # Mark as Hit-For-Pass for the next 2 minutes
208191 set beresp.ttl = 120s ;
209192 set beresp.uncacheable = true ;
210- }
193+ }
211194
212- # If the cache key in the Magento response doesn't match the one that was sent in the request, don't cache under the request's key
213- if (bereq.url ~ "/graphql" && bereq.http.X-Magento-Cache-Id && bereq.http.X-Magento-Cache-Id != beresp.http.X-Magento-Cache-Id ) {
214- set beresp.ttl = 0s ;
215- set beresp.uncacheable = true ;
216- }
195+ # If the cache key in the Magento response doesn't match the one that was sent in the request, don't cache under the request's key
196+ if (bereq.url ~ "/graphql" && bereq.http.X-Magento-Cache-Id && bereq.http.X-Magento-Cache-Id != beresp.http.X-Magento-Cache-Id ) {
197+ set beresp.ttl = 0s ;
198+ set beresp.uncacheable = true ;
199+ }
217200
218201 return (deliver );
219202}
220203
221204sub vcl_deliver {
222- if (resp.http.x-varnish ~ " " ) {
205+ if (obj.uncacheable) {
206+ set resp.http.X-Magento-Cache-Debug = "UNCACHEABLE" ;
207+ } else if (obj.hits ) {
223208 set resp.http.X-Magento-Cache-Debug = "HIT" ;
224209 set resp.http.Grace = req.http.grace ;
225210 } else {
0 commit comments