pistacchio
pistacchio

Reputation: 58953

Django caching - purge cache

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.

Upvotes: 1

Views: 372

Answers (2)

Suor
Suor

Reputation: 3055

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

Upvotes: 0

dokkaebi
dokkaebi

Reputation: 9190

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

Upvotes: 1

Related Questions