简体   繁体   English

为什么Django的缓存可以与locmem一起工作但是memcached失败了?

[英]Why would Django's cache work with locmem but fail with memcached?

Using Django's cache with locmem (with simple Python classes as values stored in lists/tuples/maps) works perfectly but does not work with memcached. 使用带有locmem的Django缓存(使用简单的Python类作为存储在lists / tuples / maps中的值)可以很好地工作,但不能与memcached一起使用。

Only a fraction of the keys (despite ample memory allocated and large timeouts) make their way into memcached, and none of them appear to have any associated value. 只有一小部分键(尽管分配了足够的内存和大的超时)进入memcached,并且它们都没有任何相关的值。

When they are retrieved, no value is returned and they are removed from the cache. 检索它们时,不返回任何值,它们将从缓存中删除。

Forcing a value of "hi" makes those that appear in the cache retrievable, but does not account for why most of the keys are simply not there. 强制值为“hi”使得出现在高速缓存中的那些可检索,但不考虑为什么大多数键根本不存在。

Questions: 问题:

  1. Why do only certain keys end up in memcached and others not, even when all values are set to "hi"? 为什么只有某些键最终在memcached中而其他键不在,即使所有值都设置为“hi”?
  2. Is there any way to enable more logging or error reporting? 有没有办法启用更多日志记录或错误报告? (everything seems to fail silently) (一切似乎都默默地失败)
  3. Why do the Python classes serialize correctly to locmem but do not end up in Memcached? 为什么Python类正确地序列化到locmem但不是最终在Memcached中?

To find out what's going on, run memcached -vv 2>/tmp/mc_debug_log (I'm assuming you're on some sort of Unixy system) and run it for a short time -- you'll find detailed information in that logfile when you're done. 要了解发生了什么,运行memcached -vv 2>/tmp/mc_debug_log (我假设您使用的是某种Unixy系统)并运行它很短的时间 - 您将在该日志文件中找到详细信息当你完成了。

Depending on what Python interface to memcached you're using, it may be that only strings are supported as values (as in the StringClient module in cmemcache ) or that all pickleable objects are (with the overhead of pickling and unpickling of course), as in the more general Client module in the same cmemcache, GAE's memcache , and python-memcached ; 根据什么Python接口您使用的是memcached的,它可能是唯一的字符串作为值的支持(如StringClient模块cmemcache )或所有与pickle对象(含酸洗,当然在unpickle的开销),如在同一个cmemcache中更一般的Client模块,GAE的memcachepython-memcached ; if you're only able to use strings as values, presumably you're using an interface of the former type? 如果你只能使用字符串作为值,可能你正在使用前一种类型的接口?

Apparently, keys can not have spaces in them: 显然,密钥不能包含空格:

http://code.djangoproject.com/ticket/6447 http://code.djangoproject.com/ticket/6447
http://blog.pos.thum.us/2009/05/22/memcached-keys-cant-have-spaces-in-them/ http://blog.pos.thum.us/2009/05/22/memcached-keys-cant-have-spaces-in-them/

As soon as I used a key with a space in it, everything became unpredictable. 一旦我使用了带有空格的钥匙,一切都变得无法预测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM