I have an issue with Varnish 4.1.1. I need expire static content based in TTL. The vcl_backend_response block have the following settings:
sub vcl_backend_response {
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
if (beresp.status == 301 || beresp.status == 302) {
set beresp.http.Location = regsub(beresp.http.Location, ":[0-9]+", "");
}
if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {
return (abandon);
}
if (bereq.url ~ "^https?:\/\/(www\.)?sample\.com(\/.*)?$|^https?:\/\/((www\.)?(media|media1)\.)?sample\.com(\/.*)?$") { // This code filter my URL
if (bereq.url ~ "^[^?]*\.(css|js)(\?.*)?$") { // This code store css and js
unset beresp.http.set-cookie;
if (beresp.ttl <= 0s || beresp.http.Set-Cookie || beresp.http.Surrogate-control ~ "no-store" || (!beresp.http.Surrogate-Control && beresp.http.Cache-Control ~ "no-cache|no-store|private") || beresp.http.Vary == "*") {
set beresp.ttl = 1m;
set beresp.uncacheable = true;
return (deliver);
}
}
if (bereq.url ~ "^[^?]*\.(jpeg|jpg|gif|png)(\?.*)?$") {// This code store images
unset beresp.http.set-cookie;
if (beresp.ttl <= 0s || beresp.http.Set-Cookie || beresp.http.Surrogate-control ~ "no-store" || (!beresp.http.Surrogate-Control && beresp.http.Cache-Control ~ "no-cache|no-store|private") || beresp.http.Vary == "*") {
set beresp.ttl = 1m;
set beresp.uncacheable = true;
return (deliver);
}
}
The above code works fine but the objects don´t expire based in the TTL defined. The storage parameter in Varnishstat Agent doesn´t update the field. Nevertheless, the following code does works correctly (clear all cache):
sub vcl_backend_response {
set beresp.ttl = 1m;
return(deliver);
}
My question is: Is it normal this behavior in varnish?
Regards.