Django caching - purge cache

2019-08-13 11:49发布

I want a simple behaviour from the caching mechanism, but I can't find a way to obtain it. I'd be fine with per-site or per-view caching, but I want some sort of control on when to invalidate cache.

For example, imagine that I have the simplest kind of site, a blog. Until I submit a new post, the frontpage doesn't change, so I'm ok with the HTML to be cached for days, but I'd like a way to say "refresh the cache now" whenever I submit a new post, so that the first call to my site after the new submission doesn't use the cached HTML but produces a new page that is going to be used till my next blog post.

How to do this? Thanks

EDIT:

cache.clear() works well and as expected, but I'd like a more "specific" option where I can specify what view to expire, not the whole cache. thanks.

2条回答
小情绪 Triste *
2楼-- · 2019-08-13 12:28

Looks like this will work. There is some more in depth explanation in that thread as well.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-13 12:34

You can also take a look at advanced caching solutions like cacheops or cache-machine. These will handle invalidation for you.

查看更多
登录 后发表回答