参考:
- http://lesliezhu.github.io/public/2016/04/19/django-cache.html
- http://www.opscoder.info/django_cache.html
示例
CACHES = { "redis": { "BACKEND": "redis_cache.cache.RedisCache", "LOCATION": "127.0.0.1:6379", "OPTIONS": { "CLIENT_CLASS": "redis_cache.client.DefaultClient", } }, ‘memcache‘: { ‘BACKEND‘: ‘django.core.cache.backends.memcached.MemcachedCache‘, ‘LOCATION‘: ‘127.0.0.1:11211‘, ‘options‘: { ‘MAX_ENTRIES‘: 1024, } }, ‘default‘: { ‘BACKEND‘: ‘django.core.cache.backends.locmem.LocMemCache‘, ‘LOCATION‘: ‘unique-snowflake‘, ‘options‘: { ‘MAX_ENTRIES‘: 1024, } } }
使用
from django.core.cache import get_cache cache = get_cache(‘redis‘) #cache = get_cache(‘memcache‘) #cache = get_cache(‘default‘) #赋值 cache.set(key, value, timeout) #.................. #取值 cache.get(key)
EOF
时间: 2024-10-31 23:39:25