从Django的缓存中删除特定的项目? [英] Removing specific items from Django's cache?

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

问题描述

我正在使用网站宽度缓存, memcached 作为后端。当底层数据库对象发生变化时,我想使缓存中的页面无效。

I'm using site wide caching with memcached as the backend. I would like to invalidate pages in the cache when the underlying database object changes.

如果页面名称更改,那么我将使整个缓存无效(因为它会影响每个页面上的导航)笨拙但足以满足我的需要。

If the page name changes then I would invalidate the whole cache (as it affects navigation on every page. Clumsy but sufficient for my needs.

如果只是页面内容发生变化,那么我想要使该页面的缓存无效。

If just the page content changes then I'd like to invalidate the cache of just that page.

有一个简单的方法吗这个?

Is there an easy way to do this?

推荐答案

tghw的解决方案实际上不起作用,因为缓存键不是绝对路径,关键是从绝对路径和HTTP标头。请参见此问题例如。

tghw's solution does not actually work, because the cache key is NOT the absolute path. The key is calculated from the absolute path and the HTTP headers. See this question for an example.

这篇关于从Django的缓存中删除特定的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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