Avoid cache on zero-bytes-returned?

Jonathan Matthews contact at jpluscplusm.com
Wed Mar 13 14:40:00 UTC 2013

On 13 March 2013 14:15, AJ Weber <aweber at comcast.net> wrote:
> Is there a way to leave my default caching enabled, but tell nginx to NOT
> cache zero-byte results?  If the correct content is available in the cache,
> I want it returned without going to the back end, but in my case (at least),
> a zero-byte result for a status=200 is not valid.

It looks to me like
is what you need to use.
If the backend is returning a Content-Length header, you could refer
to that. If not, you may have to get creative in assembling a map{}

FWIW, a 200 with an empty body is, (I believe) invalid. It should be a
204. If your backend is misbehaving, you might like to fix it before
mitigating the problem inside your reverse-proxy. Remember: broken
gets fixed, but shitty lives forever ...

Jonathan Matthews // Oxford, London, UK

More information about the nginx mailing list