[英]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: 问题:
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的memcache和python-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.