Old thread: Cache for non-cookie users and fresh for cookie users
mdounin at mdounin.ru
Thu Feb 9 08:49:50 UTC 2012
On Thu, Feb 09, 2012 at 12:34:33PM +0530, Quintin Par wrote:
> Picking up an old thread for caching
> Igor talks about caching by
> “No, currently the single way is:
> 1) add the cookie in proxy_cache_key
> proxy_cache_key "http://cacheserver$request_uri $cookie_name";
> 2) add "X-Accel-Expires: 0" in response with the cookie.”
> But from my understanding of “*X-Accel-Expires” *it expires the cache in
> the cache repository as given below
> “Sets when to expire the file in the internal Nginx cache, if one is used.”
> Does this not mean that when I set cookie and pass “X-Accel-Expires: 0” it
> expires the cache for the non logged in user too, for that cache key? A new
> cache entry will then have to be created, right?
No. X-Accel-Expires will prevent the particular response from
being cached, but won't delete existing cache entry.
> Should I go with “Cache-Control: max-age=0” approach?
The only difference between "X-Accel-Expires: 0" and
"Cache-Contro: max-age=0" is that the former won't be passed to
As for the use-case in general (i.e. only use cache for users
without cookie), in recent versions it is enough to do
I.e.: don't respond from cache to users with cookie
(proxy_cache_bypass), don't store to cache responses for users
with cookie (proxy_no_cache).
Moreover, responses with Set-Cookie won't be cached by default,
too. So basically just placing the above into config is enough,
no further changes to a backend code required.
More information about the nginx