我正在为django项目使用视图缓存.
它说缓存使用URL作为密钥,所以我想知道如果用户更新/删除对象,如何清除其中一个密钥的缓存.
例如:用户将博客帖子发布到domain.com/post/1234/..如果用户编辑了该文章,我想通过在保存编辑后的帖子的视图末尾添加某种删除缓存命令来删除该URL的缓存版本.
我正在使用:
@cache_page(60 * 60)
def post_page(....):
Run Code Online (Sandbox Code Playgroud)
如果post.id是1234,似乎这可能会起作用,但它不是:
def edit_post(....):
# stuff that saves the edits
cache.delete('/post/%s/' % post.id)
return Http.....
Run Code Online (Sandbox Code Playgroud)