This topic is very interesting.
I've got a similar problem.
I' serving stale while updating and it's fine.
My cache uses inactive=10m, but some items are cached for 1s and others for 5m.
My problem appears is this use case:
Nobody try to get the cache item for 9m for instance... than the first request will get a 9m old stale item... this is not acceptable, and I'm not finding a wayt to configure a behavior in which the expire cached content is served as STALE for an ammount o time.
As stated here as SHOULD:
Note that "stale" implies that the response will have a non-zero Age
header and a warning header, as per HTTP's requirements.
If delta-seconds passes without the cached entity being revalidated,
it SHOULD NOT continue to be served stale, absent other information.
Under heavy load stale machanism is fine, but without request the risk is to serve an un-needeed STALE.
In my understandings:
my cache item is valid for 1 sec.
after 1 sec I serve a STALE while background updating
next request while get the updated cache item.
It will be really useful a way the define the maxnim ammount of time the STALE will be served indipendently form the inactive=10m globally defined in the cache path.
Maybe I didn't look deep enought but tryed practivally every paramater in cache timing and didn't fidn anything.
tested with nginx 1.22.0 and 1.20.1
BR
Francesco