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
2
2
vcl 4 .0 ;
3
3
4
4
import std;
@@ -81,21 +81,6 @@ sub vcl_recv {
81
81
# collect all cookies
82
82
std.collect (req.http.Cookie );
83
83
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
-
99
84
# Remove all marketing get parameters to minimize the cache objects
100
85
if (req.url ~ " (\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=" ) {
101
86
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 {
173
158
}
174
159
175
160
# 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" ) {
179
162
set beresp.uncacheable = true ;
180
163
set beresp.ttl = 86400s ;
181
164
return (deliver );
@@ -198,28 +181,30 @@ sub vcl_backend_response {
198
181
unset beresp.http.set-cookie ;
199
182
}
200
183
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 == " *" ) {
207
190
# Mark as Hit-For-Pass for the next 2 minutes
208
191
set beresp.ttl = 120s ;
209
192
set beresp.uncacheable = true ;
210
- }
193
+ }
211
194
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
+ }
217
200
218
201
return (deliver );
219
202
}
220
203
221
204
sub 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 ) {
223
208
set resp.http.X-Magento-Cache-Debug = " HIT" ;
224
209
set resp.http.Grace = req.http.grace ;
225
210
} else {
0 commit comments