本文介绍了如何使用Python memcached检查Django缓存的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工具版本:




  • Python 2.6.5

  • Django 1.3.1

  • memcached 1.4.10

  • python-memcached 1.48



Memcached目前正在运行:

  $ ps -ef | grep memcache 
nobody 2993 1 0 16:46? 00:00:00 / usr / bin / memcached -m 64 -p 11211 -u nobody -l 127.0.0.1



我正在使用memcached和python memcached与我的Django proj,我已经设置如下: settings.py

  CACHES = {
'default':{
'BACKEND':'django.core.cache.backends.memcached.MemcachedCache' ,
'LOCATION':'127.0.0.1:11211',
'TIMEOUT':86400,
},
}
/ pre>

我已经将缓存设置在代码中:

  from django.core.cache import cache 
cache.set('countries',['Canada','US'])

然后我打开一个Django shell来检查缓存的内容:

 > >>从django.core.cache导入缓存
>>>缓存中的'countries'
True
>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'],debug = 1)
>>> mc.get('countries')
>>>

当我使用Django的缓存时,国家键存在。但是,当我使用Python的memcache时,我不会为国家任何东西。我以前做错了什么?

解决方案

Django使用冒号前缀缓存键。如果没有帮助,您可以检查memcached 。 / p>

Tools version:

  • Python 2.6.5
  • Django 1.3.1
  • memcached 1.4.10
  • python-memcached 1.48

Memcached is currently running:

$ ps -ef | grep memcache
nobody    2993     1  0 16:46 ?        00:00:00 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1

I'm using memcached and python memcached with my Django proj and I've set it like the following in settings.py:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
        'TIMEOUT': 86400,
    },
}

I've set the cache in the code:

from django.core.cache import cache
cache.set('countries', ['Canada', 'US'])

I then open a Django shell to inspect the content of the cache:

>>> from django.core.cache import cache
>>> 'countries' in cache
True
>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'], debug=1)
>>> mc.get('countries')
>>>

When I use Django's cache, countries key exists. However, when I use Python's memcache, I don't get anything for countries. What am I doing wrong above?

解决方案

Django prefixes cache keys with a colon. You can inspect memcached like so if this doesn't help.

这篇关于如何使用Python memcached检查Django缓存的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:17