Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common varnish: difference between beresp & resp, bereq & req; req.ttl & beresp.ttl

Tell me please, whats the difference between these concepts? I didn't found any answers in documentations of Varnish. They just operative these concepts, nothing more.

And what is better to use for caching: beresp.ttl or max-age in Cache-control header?

If you can do it with little examples - do it please :)

like image 377
Nikita_kharkov_ua Avatar asked Nov 16 '16 09:11

Nikita_kharkov_ua


People also ask

What is varnish age?

Age. Varnish adds an 'Age' header to indicate how long the object has been kept inside Varnish. You can grep out 'Age' from varnishlog with varnishlog -I RespHeader:^Age .

What is Beresp grace?

Defines how long an object can remain overdue and still have Varnish consider it for grace mode. Fastly has implemented beresp.


1 Answers

req: The request values as soon as it arrive at Varnish.

bereq: The request that goes to the backend. All variables from req are automatically assigned to bereq. However, those values may slightly differ, because Varnish may modify client requests. For example, HEAD requests coming from clients may be converted to GET requests towards the backend.

beresp: The backend respose. Any changes in beresp affect resp and obj which is the cached object. Tip: If you want to get any additional info to your object, set it to beresp.

resp: The response that is delivered to the client. All the beresp values are passed on to resp.

After all the names explained it is elementary to conclude that req.ttl is the TTL received from the request and it means nothing unless you configure it differently. beresp.ttl is the one that is going to set the TTL of your object.

As about the what's best for caching, Varnish already gets the max-age and sets it to beresp.ttl. So in the end there's no difference. The difficulty of employing this is that some web apps do not treat the max-age correctly and end up always sending nocache causing Varnish to cache nothing. In those cases you should ignore what comes in beresp.http.cache-control and set your own TTL.

Some relevant reading to deepen further in this topic can be found in the Varnish Book subroutines section.

like image 189
alejdg Avatar answered Sep 29 '22 16:09

alejdg