Avoid cache on zero-bytes-returned?

Jonathan Matthews contact at jpluscplusm.com
Wed Mar 13 15:12:14 UTC 2013

On 13 March 2013 15:02, AJ Weber <aweber at comcast.net> wrote:
> On 3/13/2013 10:40 AM, Jonathan Matthews wrote:
>> It looks to me like
>> http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_no_cache
>> 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{}
>> variable.
> I looked at that, but it appears that it only tests for the existence of the
> variable/header.  Content-Length should be there all the time.

The docs I linked to have this to say: "If at least one value of the
string parameters is not empty and is not equal to “0” then the
response will not be saved"

So if content-length is always present (and sometimes "0") I would try this:

map $upstream_http_content_length $map_upstream_cache_buster {
  default 0;
  0         1;
server {
  proxy_no_cache $map_upstream_cache_buster;

Or something like that; you get the idea.

Jonathan Matthews // Oxford, London, UK

More information about the nginx mailing list