I noticed that my per-site caching does not work because page response headers include:
Vary:Cookie
Since I have google analytics installed it will update cookie on every page load which would make cache unusable.
I am not sure if I have added Vary:Cookie to page response headers implicitly or where it comes from. Any help appreciated.
Django 1.3.1
UPDATE:
it turns out that when session middleware is included and session is accessed, it will add Vary:Cookieheader to response. In my case reason is that 3rd party app is accessing session.
The question is not really formulated as a question 🙂 but I thought I would point out a few things.
Django cache is not sensitive to cookies by default. But you can tell him to be by setting the
vary_on_*decorators.This means that the per-site cache you are talking about is something else – you mention google analytics, though it’s not really clear how related that is to caching itself.
Thus you probably (?) have some caching fronted.
If you were to be using nginx or varnish, you can customize the way
varyaffects the cache, and with nginx you can also remove it from the response so that the client does not receive it (including google analytics).If you simply want javascript not to see the session cookies, there’s a specific setting:
SESSION_COOKIE_HTTPONLY.You should have a per-url-pattern strategy where you adapt cache behaviour to pages that depend, or not, to a logged-in user, by using or ignoring the Vary and Expire headers.
[edit]
using Nginx for caching
If you are using nginx as a frontend and want to cache with it, there’s a very simple way to force caching for views where the cookies are unnecessary using :
you will need to define a cache, for more information checkout: https://serverfault.com/questions/30705/how-to-set-up-nginx-as-a-caching-reverse-proxy
With uwsgi very similar settings apply, just they are prefixed uwsgi; checkout the uwsgi doc, but considering it is less verbose than the “proxy” doc I started from that as an example.
If you want to completely “remove” cookies you can:
but I’m not sure this is what you want to do!
On the other hand, if you want to better control browser’s cache too, you could re-set the vary header as you want:
and you can even reset it to something else: