【问题标题】:Django cache NotImplementedErrorDjango缓存NotImplementedError
【发布时间】: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.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>>

什么鬼?

【问题讨论】:

  • 那里,似乎调试工具栏以某种方式干扰。我禁用了debug_toolbar.panels.cache.CachePanel,它现在可以工作了。

标签: python django caching django-debug-toolbar


【解决方案1】:

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

from django.core.cache import cache

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

【讨论】:

  • 是的,我试过from django.core.cache import cache
  • 这是一条线索,在应用程序内部,cache.clear&lt;bound method CacheStatTracker.clear of &lt;CacheStatTracker for &lt;redis_cache.cache.RedisCache object at 0x10a39dbd0&gt;&gt;&gt;。在控制台中,它是&lt;bound method RedisCache.clear of &lt;redis_cache.cache.RedisCache object at 0x10bf1e0d0&gt;&gt;
猜你喜欢
  • 2016-06-20
  • 1970-01-01
  • 2014-02-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-29
  • 1970-01-01
  • 1970-01-01
  • 2013-08-18
相关资源
最近更新 更多