无法在 django python 中使用缓存

我想在 django 中缓存,所以我使用低级 API 缓存,但即使添加后也没有显示


>>> from django.core.cache import cache

>>> cache.set('my_key', 'hello, world!')

>>> cache.get('my_key')

>>> print(cache.get('my_key'))

None

>>>

在我的设置.py


CACHES = {

    'default': {

        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',

        'LOCATION': '127.0.0.1:11211',

    }

}

即使我使用cache.add('my_key', 'hello, world!', 30)它也会返回 false


元芳怎么了
浏览 184回答 2
2回答

蓝山帝景

CACHES = {    'default': {        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',    }}这个设置对我有用

撒科打诨

您可以尝试设置超时:CACHES = {    'default': {        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',        'LOCATION': 'exchange_rate_cache',        'TIMEOUT': 604800  # 7 days    }}您可以将超时设置为“无”以将其完全删除。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python