caching - Varnish Cache - Cache a 403 response -
we're using varnish in front of aws s3 bucket , things have been running we've had 98.4% hit rate has saved large s3 bills!
our applications need able make requests files may or may not exist yet. when happens varnish make request s3 , receive 403 (permission denied) response. catch response in vcl_error function allows display custom error message. since we're expecting 400-500 requests per second 40% being files don't exist yet run cost issues s3.
my question is, possible have varnish remember file returned 403 , return cached response? varnish wait 5 minutes before requesting file backend. we're running varnish 3.
i've read documentation appears sugest can use "set obj.ttl = 5m;" in vcl_error function doesn't seem work.
thanks! alan
yes, can cache it. check status code of response s3 , set ttl.
varnish 3:
sub vcl_fetch { if (beresp.status == 403 || beresp.status == 404 || beresp.status >= 500) { set beresp.ttl = 3s; } }
varnish 4:
sub vcl_backend_response { if (beresp.status == 403 || beresp.status == 404 || beresp.status >= 500) { set beresp.ttl = 3s; } }
Comments
Post a Comment