Django 中 Memcached 上的会话 - Memcached 中没有项目
我正在使用 memcached 在 Django 中设置会话,登录后,缓存中没有出现任何项目。
我可以使用 telnet localhost 11211
连接到我的 memcached 实例,并且 stats
显示该进程正在运行。我的缓存设置如下:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211' # can also be a list of locations
}
}
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
并且我确实为缓存设置了数据库。会话显示在数据库中。 (当仅使用 backends.cache 时,数据库或缓存中不会显示任何内容。)
那么这是预期的行为吗?我是否必须在会话密钥中存储一些特殊的内容才能注册?
I'm setting up sessions in Django using memcached, and after logging in, no items appear in the cache.
I can connect to my memcached instance with telnet localhost 11211
and stats
says the process is running. My cache settings are as follows:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211' # can also be a list of locations
}
}
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
and I do have the database set up for the caching. The sessions show up in the database. (when using just backends.cache
nothing shows up in the database or the cache.)
So is this the expected behavior? Do I have to store something special in the session key for it to register?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 1.2 并正在阅读 1.3 的文档。
在 1.2 中,缓存看起来像这样:
CACHE_BACKEND = "memcached://127.0.0.1:11211/"
而不是缓存字典。I'm using 1.2 and was reading the docs for 1.3.
In 1.2, the cache looks like this:
CACHE_BACKEND = "memcached://127.0.0.1:11211/"
instead of the caches dictionary.您还需要将两个中间件类添加到 MIDDLEWARE_CLASSES 设置中,如下所述:
https://docs.djangoproject。 com/en/dev/topics/cache/?from=olddocs#the-per-site-cache
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)
You also need to add two middleware classes into your MIDDLEWARE_CLASSES setting as described here:
https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#the-per-site-cache
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)
使用 django.core.cache.backends.locmem.LocMemCache 如下
Use
django.core.cache.backends.locmem.LocMemCache
as below