Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update settings.py #2473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

eternalstop
Copy link

Add "django.middleware.cache.UpdateCacheMiddleware" at first line;
Add "django.middleware.cache.FetchFromCacheMiddleware" at last line;
These two middleware must be added, otherwise the cache will not work.
django 4.2.8

Add "django.middleware.cache.UpdateCacheMiddleware" at first line
Add "django.middleware.cache.FetchFromCacheMiddleware" at last line

These two middleware must be added, otherwise the cache will not work.
@LeoQuote
Copy link
Collaborator

谢谢pr, 如果方便的话, 请补充相关的文档, 失败的单元测试也请关注一下

@eternalstop
Copy link
Author

对不起,我之前的描述有点问题,如果想要页面缓存,需要在MIDDLEWARE配置块中加入这两个中间件,且位置最好是这样:
首行加入"django.middleware.cache.UpdateCacheMiddleware"
尾行加入"django.middleware.cache.FetchFromCacheMiddleware"
否则即使加了缓存也不会生效,我的python版本是3.11.2,django版本是4.2.8,我添加的缓存配置是redis缓存,如下
env = environ.Env(
CACHE_URL=(str, "redis://default:***********@127.0.0.1:6379/11?KEY_PREFIX=archery"),
)
添加前后查看过redis key对比,确实添加中间件后页面缓存生效了,archery框架本身的缓存配置是否是给djangoq用的?没有作为页面缓存用?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants