4、Django缓存
Django-Redis
安装
作为session后端
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"作为cache后端
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}应用
单独视图缓存
模板局部缓存:
在路由URLConf中使用cache
其他缓存方式
Memcached 缓存实战
REDIS 缓存实战
文件系统缓存实战
本地内存缓存实战
Last updated