Hi,<div>For a given location, I want the requests to be cached only if a particular cookie is not present. How do I achieve that with nginx?</div><div>Currently I&#39;m trying following config</div><div><br></div><div><div>

    location /album {</div><div>        if ($cookie_logintoken ~* &quot;&quot;) {</div><div>            set $cache_key $scheme$proxy_host$uri$is_args$args;</div><div>        }</div><div><br></div><div>        proxy_pass_header  Set-Cookie;</div>

<div>        proxy_cache_key $cache_key;</div><div>        proxy_cache mem_pool;</div><div>        proxy_cache_valid  200 5m;</div><div>        proxy_pass http://$backend$uri$is_args$args;</div><div><br></div><div>    }</div>

<div><br></div><div><br></div><div>Here, if the logintoken cookie is not present in the request, the cache_key variable is set to a valid key string. If the cookie is present, cache_key it will be undefined. So I expect the proxy_cache_key directive to not cache that request. But it seems it still caches the request with empty key. Is this the expected behavior? Is there any solution this problem?</div>

<div><br></div><div>Also, with &quot;proxy_cache_valid 200 5m;&quot; I expect only 200 responses to be cached. But I&#39;m seeing 30x responses also getting cached.</div><div><br></div><div><b>nginx version 0.7.64</b></div>

<div><br></div>Thanks,<br>-- <br>Vinay</div>