I’m setting up a Django site to use memcached, via Django’s site-wide caching MiddleWare.
I planned to store pages in memcached for a very long time (because they don’t change very often, and because my whole site should comfortably fit into a relatively small amount of memory), and amend my code to delete pages from memcached when the data on those pages does change (to avoid stale pages).
However, Django’s MiddleWare sets the Cache-Control and Expires HTTP headers on its responses to the same values that memcached uses for its expiry policy. That means that if I set a very long expiry for cached pages in memcached, end users’ browsers will use that expiry too, making them more likely to get stale data.
Can I stop Django’s MiddleWare from doing this?
You can add
decorator to each of your views to make browsers validate their cache contents every time page is loaded. It is available by importing
After that, if content on server is changed, then browser will redownload page from server.