Old thread: Cache for non-cookie users and fresh for cookie users

Nginx User nginx at nginxuser.net
Fri Feb 10 22:24:58 UTC 2012


On 10 February 2012 20:47, Max <nginxyz at mail.ru> wrote:
> The default behaviour is not to cache POST method request responses,
> but I turned caching of POST method request responses ON, so I had
> to make sure the cache is bypassed for POST method requests (but
> not for GET or HEAD method requests!). All POST method requests
> are passed on to the backend without checking for a match in the
> cache, but - CONTRARY to the default behavior - all POST method
> request responses are cached.
>
> Without the @post_and_refresh_cache location block and without
> the proxy_cache_bypass directive, nginx would check the cache
> and return the content from the cache (put there by a previous
> GET request response, for example) and would not pass the POST
> method request on to the backend, which is definitely not what
> you want in this case.

Your config would do what the OP wanted but it would be nicer, I
think, if the POST request simply invalidated the existing cached
content and then for the content to be cached only if and when there
is a GET request for that item. I.E., for the cache validity to start
when there is a request to view the item.
Also avoids using $uri as key which can lead to cache pollution with
frontend controllers etc.

An internal call to a proxy_purge location could do this ... maybe as
a post_action. There will be no need for the proxy_bypass



More information about the nginx mailing list