我有一个python django网络服务器,我试图使用memcached来加快速度。
我已下载并安装了memcached,并启动了一个名为virtual的用户,如下所示:
/usr/local/bin/memcached -u virtual &
在django setting.py上的,我把memcached服务器放在这个:
MEMCACHE_HOSTS = ['192.168.101.1:11211']
我可以telnet 192.168.101.1 11211和统计数据,我确实在那里看到一些统计数据等。
我如何真正了解我的django服务器是否使用了memcached?是否有我可以查看的目录或一些要确认的文件?
感谢您的任何见解。
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.
答案 0 :(得分:5)
您可以在Django的shell(python manage.py shell
)中测试缓存:
from django.core.cache import cache
cache.set('foo', 'bar', 600)
cache.get('foo')
如果这有效,则意味着缓存正常工作。否则会引发错误。
其他选项是为memcached安装监控工具(即memcache-top),并在使用您的应用时检查memcached中是否发生了某些事情。