Mark stale cache content as "invalid" on non-cacheable responses
rmind at noxt.eu
Tue Nov 17 17:25:30 UTC 2015
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.:
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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the nginx-devel