【发布时间】:2015-04-16 20:55:40
【问题描述】:
我可以在 Python shell 中做到这一点:
from django.core.cache import *
cache.clear()
但是当我从signals.py尝试这个时
from django.core.cache import *
....
....
def clear_cache(sender, instance, **kwargs):
if sender.__name__ in ['Foo', 'Bar']:
cache.clear()
我明白了:
NotImplementedError at /edit/bar/
subclasses of BaseCache must provide a clear() method
我正在使用 redis,但我在使用 memcached 时遇到了同样的问题。
就在错误处,我可以看到cache = <django.core.cache.DefaultCacheProxy object at 0x10e566e90>
我一定是做错了什么?
编辑:
这是一个线索。
从内部signals.py,cache.clear 是:
<bound method CacheStatTracker.clear of <CacheStatTracker for <redis_cache.cache.RedisCache object at 0x10a39dbd0>>>
在控制台中:
<bound method RedisCache.clear of <redis_cache.cache.RedisCache object at 0x10bf1e0d0>>
什么鬼?
【问题讨论】:
-
那里,似乎调试工具栏以某种方式干扰。我禁用了
debug_toolbar.panels.cache.CachePanel,它现在可以工作了。
标签: python django caching django-debug-toolbar