Django Cache cache.set不存储数据

Zac*_*lly 17 django memcached caching

当我跑python manage.py shell,然后:

from django.core.cache import cache
cache.set("stack","overflow",3000)
print cache.get("stack")

(output: ) None
Run Code Online (Sandbox Code Playgroud)

我尝试重启memcache,这就是我的设置:

CACHES = { 
  'default' : { 
     'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 
     'LOCATION' : '127.0.0.1:11211',
  }
}
Run Code Online (Sandbox Code Playgroud)

mra*_*agh 3

确保它使用正确的缓存。尝试一下from django.core.cache import caches,然后查看内容caches.all()。它应该只有一个django.core.cache.backends.memcached.MemcachedCache.
如果是,请尝试直接访问它,例如

from django.core.cache import caches  
m_cache = caches.all()[0]
m_cache.set("stack","overflow",3000)
m_cache.get("stack")
Run Code Online (Sandbox Code Playgroud)

这可能无法解决您的问题,但至少会让您更接近调试 Memcached,而不是 Django 的缓存代理或您的配置。