我正在使用視圖緩存的Django項目。在Django中清除特定的緩存
它說緩存使用的URL作爲關鍵,所以我想知道如何清除一個密鑰的緩存,如果用戶更新/刪除對象。
舉例:用戶發佈博客文章爲domain.com/post/1234/
..如果用戶編輯了該文件,我想通過在視圖末尾添加某種類型的delete cache命令來刪除該URL的緩存版本保存已編輯的帖子。
我使用:
@cache_page(60 * 60)
def post_page(....):
如果post.id是1234,它看起來這可能會奏效,但它不是:
def edit_post(....):
# stuff that saves the edits
cache.delete('/post/%s/' % post.id)
return Http.....
我的猜測是,你正在使用的密鑰是不正確的。您可以嘗試在您的memcached服務器上使用[此腳本](http://simple-and-basic.com/2008/10/list-memcached-keys.html)列出密鑰。一旦你有合適的密鑰,再次嘗試cache.delete(key)方法。 – stephenmuss 2012-01-09 06:07:54
以下是更新後的django緩存文檔的鏈接: [Django Caches](https://docs.djangoproject.com/en/1.9/topics/cache/#django-s-cache-framework) – turtlefranklin 2016-06-24 13:38:43