Django 缓存 cache基本使用

时间:2019-11-28 10:20:32   收藏:0   阅读:1683

1.设置setting

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://10.133.3.34:6379/1",
        ‘TIMEOUT‘: 50,  # 过期时间(秒)
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            # "PASSWORD": "123456"  # Redis 密码
        }
    }
}

2.cache基本使用

from django.core.cache import cache

设置:cache.set(键,值,有效时间 秒)
获取:cache.get(键)
删除:cache.delete(键)
清空:cache.clear() 



from django.views.decorators.cache import cache_page
 
@cache_page(60 * 15)
def my_view(request, param):
    # ...

  

原文:https://www.cnblogs.com/yoyo1216/p/11946899.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!