1、安装memcached
sudo apt-get install memcached
由于memcached依赖于libevent;因此,还需要安装libevent,命令如下:
sudo apt-get install libevent-dev
2、安装python3-memcached
pip3 install python3-memcached
3、配置Django
settings.py
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': [
'127.0.0.1:11211',
]
}
}
4、启动memcached
sudo service memcached start
5、为页面函数添加缓存装饰器
@cache_page(60 * 15)
def index(request):
pass
来源:CSDN
作者:请叫我算术嘉
链接:https://blog.csdn.net/ssjdoudou/article/details/104032599