您如何确认django正在使用memcached? [英] How do you confirm django is using memcached?

查看:50
本文介绍了您如何确认django正在使用memcached?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python django网络服务器,我正在尝试使用memcached使其速度更快.

I have a python django webserver that I am trying to use memcached to make it faster.

我已经下载并安装了memcached,并按如下所示启动了一个名为virtual的用户:

I have downloaded and installed memcached and started it a user called virtual as follows:

/usr/local/bin/memcached -u virtual & 

在django setting.py上,我将内存缓存服务器设置为:

on the django setting.py, I have put the memcached server as this:

MEMCACHE_HOSTS = ['192.168.101.1:11211']

我可以进行telnet 192.168.101.1 11211和统计信息,我确实在其中看到了一些统计信息,等等.

I can do telnet 192.168.101.1 11211 and stats, I do see some statistics there etc.

我怎么真正知道我的django服务器是否使用了memcached?有没有我可以查看的目录或一些文件可以确认?

How do I really know if my django server utilizing the memcached? Is there directory that I can look at or some files to confirm?

谢谢您的见识.

manage.py的内容:

content of manage.py:

#!/usr/bin/env python
import os
import sys

from django.core.management import execute_from_command_line


if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

从命令行:

phthon

from django.core.management import execute_from_command_line

当我这样做时:

from django.core.cache import cache

我得到这些错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib64/python2.6/site-packages/django/core/cache/__init__.py", line 69, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "/usr/local/lib64/python2.6/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/usr/local/lib64/python2.6/site-packages/django/conf/__init__.py", line 47, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

推荐答案

您可以在Django的shell中测试缓存( python manage.py shell ):

You can test cache in Django's shell (python manage.py shell):

>>> from django.core.cache import cache
>>> cache.set('foo', 'bar', 600)
>>> cache.get('foo')
'bar'

如果 cache.get()返回设置值,则表示高速缓存正在正常工作.否则,它将返回 None .

If cache.get() returns the set value it means that cache is working as it should. Otherwise it will return None.

另一个选择是使用 $ memcached -vv 启动memcached,因为它将所有对缓存的访问记录到终端.或者,您也可以安装用于memcached的监视工具(即 memcache-top )并检查使用您的应用程序时,memcached中发生了某些事情.

An other option is to start memcached with $ memcached -vv, since it will log all the cache accesses to the terminal. Or alternatively you can install monitoring tool for memcached (i.e. memcache-top) and check that something is happening in memcached while using your app.

这篇关于您如何确认django正在使用memcached?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆