Mark stale cache content as "invalid" on non-cacheable responses

Mindaugas Rasiukevicius rmind at noxt.eu
Tue Nov 17 17:25:30 UTC 2015


Hi,

Context: consider nginx used as a cache with proxy_cache_use_stale set
to 'http_500' and the 'updating' parameter set i.e. it caches errors and
serves the stale content while updating.  Suppose the upstream temporarily
responds with HTTP 504 and Cache-Control being max-age=3.  The error gets
cached, but after 3 seconds it expires.  At this point, let's say the
upstream server starts serving HTTP 200 responses, but with Cache-Control
set to 'no-cache'.

The cache manager will not LRU the expired content immediately; it will
stay in the EXPIRED state while subsequent requests will result in 200s.
Problem: if there are multiple processes racing, the ones in the UPDATING
state will serve stale 504s.  That results in sporadic errors, e.g.:

200 EXPIRED
504 UPDATING
200 EXPIRED
...

At the very least, I think the stale cache content should be marked as
"invalid" after the no-cache response (with the possibility to become
valid again if it becomes cacheable).  Whether the object should be kept
at all is something to debate.

Please find the preliminary patch attached.

-- 
Mindaugas
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ngx_stale_cache_inv.patch
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20151117/9528a49a/attachment.ksh>


More information about the nginx-devel mailing list