Old thread: Cache for non-cookie users andfresh for cookie users

Max nginxyz at mail.ru
Sat Feb 11 18:23:48 UTC 2012

11 февраля 2012, 04:07 от António P. P. Almeida <appa at perusio.net>:
> On 10 Fev 2012 17h47 WET, 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.
> If what the OP wanted was to distinguish between cached POST and GET
> request responses then just add $request_method to the cache key.

That's not what the OP wanted, and that's not what the approach
I described does. The OP wants to be able to invalidate cache entries
on demand without using 3rd party modules. Since, AFAIK, there's no
way to do that without using 3rd party modules, the alternative is to
make sure the cache is as fresh as possible. This can be done by making
sure POST method requests refresh the appropriate cache entries
automatically and/or by having special location blocks for refreshing
specific cache entries on demand.


More information about the nginx mailing list