【发布时间】:2018-08-21 12:27:39
【问题描述】:
我有一个带有注册数据库缓存的 Django 应用程序:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'exchange_rate_cache',
}
}
我希望缓存中的条目在一周后过期并被删除。要从缓存中删除一个条目,只需执行以下操作:
from django.core.cache import cache
cache.delete(key)
但是,只有当条目在缓存中存储超过 1 周时,我才必须执行此操作。
如何做到这一点?谢谢。
【问题讨论】:
-
在缓存中,可以设置一个过期时间。
-
这怎么做呢?
-
redis_time_cache = 180 cache.set(key, data, redis_time_cache)
标签: python django django-cache