Welcome! Log In Create A New Profile

Advanced

Setting "inactive" time via HTTP header

Posted by kkmm 
Setting "inactive" time via HTTP header
September 27, 2022 10:49AM
Nginx has “X-Accel-Expires” header field to set the caching time of a response in seconds. This allows caching rules to be partially controlled by the application that is generating the response. Similarly, is it possible to support a “X-Accel-Inactive” header field to control the removal of the cache entry without specifying "inactive=nnn" in proxy_cache_path? The objective is to prevent nginx from serving stale/expired application content and give control of cache removal to the upstream app.
Re: Setting "inactive" time via HTTP header
October 06, 2022 12:54PM
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
Re: Setting "inactive" time via HTTP header
October 07, 2022 03:15AM
+ follow topic
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 103
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready