gpt4 book ai didi

python - 暂时禁用 Django 缓存

转载 作者:IT老高 更新时间:2023-10-28 22:19:53 30 4
gpt4 key购买 nike

如何在每次结账时禁用 Django 缓存?

在 Django 1.3 之前,我可以通过在 settings.py 导入的 settings_local.py 中指定 CACHE_BACKEND = None 来禁用本地开发结帐的缓存。 settings_local.py 被 SVN 忽略了,所以我总是可以确保我的本地环境没有缓存,而不必担心修改 settings.py 中的缓存参数。

现在,使用 Django 1.3 和新的 CACHES = {...} 结构,设置 CACHES = NoneCACHES['default']['BACKEND'] = None 导致 Django 阻塞,设置 CACHES = {} 似乎仍然可以启用基本缓存。

最佳答案

Dummy Caching (for development) - 这实现了缓存接口(interface),但实际上并没有缓存,因此您可以在您的开发/测试站点上使用它来减少缓存并防止缓存出现错误(如果应该出现)。

Finally, Django comes with a "dummy" cache that doesn't actually cache – it just implements the cache interface without doing anything.

This is useful if you have a production site that uses heavy-duty caching in various places but a development/test environment where you don’t want to cache and don’t want to have to change your code to special-case the latter. To activate dummy caching, set BACKEND like so:

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}

关于python - 暂时禁用 Django 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7602904/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com