1

我可以从 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.pycache.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>>

有没有搞错?

4

1 回答 1

0

*您是否尝试过,而不是使用 导入所有内容:

from django.core.cache import cache

缓存文档:https ://docs.djangoproject.com/en/1.8/topics/cache/#accessing-the-cache

于 2015-04-17T00:06:09.593 回答