varnish-cache icon indicating copy to clipboard operation
varnish-cache copied to clipboard

Add std.rfc_ttl()

Open nigoroll opened this issue 2 months ago • 1 comments

From the added documentation:

Re-calculate the object timers (beresp.ttl, beresp.grace and beresp.grace) and cacheability status based on the current state of beresp as if it had been processed by core code before vcl_backend_response was called.

This is useful to get the default ttl calculations after modifications of relevant properties like beresp.status, beresp.http.Date, beresp.http.Age or beresp.http.Cache-Control.

nigoroll avatar Dec 10 '25 16:12 nigoroll

this is massively welcome. But maybe we should also offer the opposite? i.e. modify the headers to match the beresp.* properties? It's quite a bit more work and a can of worms on its own, but worth mentioning, even if it doesn't invalidate the need for this PR.

gquintard avatar Dec 10 '25 17:12 gquintard

maybe we should also offer the opposite?

Yes, some standard function to create Cache-Control based on the state of an object could be useful. Bug please let's keep this separate.

nigoroll avatar Dec 11 '25 11:12 nigoroll

I have updated the PR to also allow std.rfc_ttl() from vcl_backend_refresh, for which most of the work was to adjust the test case, because I got lured into a rabbit hole regarding ttl <= 0s being uncacheable and whether or not that still makes sense. But I got out before turning the hole into a burrow.

nigoroll avatar Dec 11 '25 18:12 nigoroll

OK with me.

bsdphk avatar Dec 15 '25 21:12 bsdphk