美文网首页
django的cache

django的cache

作者: 上帝大人 | 来源:发表于2019-09-28 20:16 被阅读0次

在settings中,使用redis作为django的缓存

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://47.100.179.209:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}
from django.core.cache import cache
cache_content = cache.get('key')
cache.set('key',value,timeout)

value 可以是任何类型的,在为首页的数据设置缓存的时候,value就是上下文context,保存的是返回模板文件中的数据。可以直接返回模板,进行渲染。

相关文章

网友评论

      本文标题:django的cache

      本文链接:https://www.haomeiwen.com/subject/otfnyctx.html