在慢长的优化网站的路途中,找到了varnish、django-redis-cache、 memcached等等,只是这路途还是很长,然而还没有解决。即使是在Django Debug Toolbar也没有找到对应的Cache。只是种种迹象表明好似是服务器的CPU问题。我还在纠结使用Varnish的问题,然而似乎没有帮助,只是有意思的是没有配置成功Varnish
Redis是一个开源、支持网络、基于内存、键值对存储数据库,使用ANSI C编写。其开发由VMware主持。根据月度排行网站DB-Engines.com的数据显示,Redis是最流行的键值对存储数据库。
A cache backend for Django using the Redis datastructure server.
Django可以用memcached,在安装了python-memcached之后可以在settings.py中添加下面的代码解决。
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': 'unix:/tmp/memcached.sock',
    }
}
1.安装
pip install hiredis
pip install django-redis-cache
2.配置
CACHES = {
    "default": {
        "BACKEND": "redis_cache.cache.RedisCache",
        "LOCATION": "unix:/tmp/redis.sock:1",
        "OPTIONS": {
            "PASSWORD": "",
            "PICKLE_VERSION": -1,   # default
            "PARSER_CLASS": "redis.connection.HiredisParser",
            "CLIENT_CLASS": "redis_cache.client.DefaultClient",
        },
    },
}
当然在,那之前还需要安装好redis
这个自然是比较简单了
1.安装redis
 yum install redis
1.进入django console
 python manage.py shell
2.测试是否能连接
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from redis_cache import get_redis_connection
>>> con = get_redis_connection('default')
>>> con
Redis<ConnectionPool<UnixDomainSocketConnection<path=/tmp/redis.sock,db=1>>>
>>>
围观我的Github Idea墙, 也许,你会遇到心仪的项目