Welcome! Log In Create A New Profile

Advanced

PROXY_CACHE: option to HIT after STALE

Posted by salavessa 
PROXY_CACHE: option to HIT after STALE
February 24, 2017 11:24PM
Hi,

I'm currently using nginx to serve stale content in the event of origin failure and there's a feature that I couldn't find and believe to be very simple to implement and, at the same time, would allow great performance improvement when the origin is returning errors or is unreachable/unresponsive: HIT after STALE.
A directive like: proxy_cache_evoke inherit | _time_;
. inherit - {keyword} revalidate cache for same amount of time of the original request
. time - revalidate cache entry for specified period of time (e.g. 60s)

The value of $upstream_cache_status, for when stale content is being served and cache time greater than 0, could be EVOKED

Test case scenario:
- origin returns 500
- cache entry exists, has expired and is still active
- proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504
- proxy_connect_timeout 2s
- proxy_ignore_headers Cache-Control Expires
- proxy_cache_valid any 1m
- proxy_cache_background_update off
- proxy_cache_lock on
- requesting "cached" page 5 times per second
* what's currently observed is that the origin gets hit every single time a request is made
! what would happen with this new functionality ("proxy_cache_evoke inherit") is that nginx would fetch the origin at most once per minute, since "proxy_cache_valid any 1m"

- same scenario as above but the origin is DOWN (connection times out)
* this gets slightly better than the previous scenario as request to the origin will be made only around every 2 seconds (because "proxy_connect_timeout 2s" and "proxy_cache_lock on"), the other requests will get an "UPDATING" cache status
! using the new functionality the result would be the same as before, i.e., origin calls for this request would be made at most once a minute ("proxy_cache_valid any 1m")

A workaround for this behavior which I've currently in place but may not be accessible to everyone is to put the nginx behind a CDN (or some other caching service, which could even be another nginx instance).

Thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 182
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready