Django缓存 - 清除缓存 [英] Django caching - purge cache

查看:302
本文介绍了Django缓存 - 清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要缓存机制的一个简单的行为,但我找不到一种方法来获取它。我会按照每个站点或每次浏览的缓存进行处理,但是我想要在何时使缓存使用某种控制。



例如,假设我有最简单的网站,一个博客。直到我提交一个新的帖子,首页不会改变,所以我可以使用HTML缓存几天,但我想要一个方法来说刷新缓存现在每当我提交一个新的帖子,所以在新的提交之后,我的网站的第一次调用不使用缓存的HTML,但生成一个新的页面将被使用,直到我的下一篇博文。



如何做?感谢



编辑



cache.clear )运行良好,按预期,但我想要一个更特定的选项,我可以指定什么视图到期,而不是整个缓存。谢谢。

解决方案

看起来像这个将工作。在这个线程中还有一些更深入的解释。


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.

解决方案

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

这篇关于Django缓存 - 清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆