django 缓存
参考rul
https://docs.djangoproject.com/en/2.1/topics/cache/
https://django-redis-chs.readthedocs.io/zh_CN/latest/
测试版本
django 1.11.5
django-redis-4.10.0
redis-3.2.0
官网介绍:
项目的setting.py里面可以通过CACHES配置缓存,django中可用的缓存系统有Memcached、数据库、文件、本地内存等
1.内存数据库Memcached
安装memcached后,还需安装数据库的
2.利用文件系统来缓存
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
3.数据库来缓存
首先创建缓存数据库表
python manage.py createcachetable
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'my_cache_table',
}
}
4. 本地的内存来当缓存
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}