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

Django cache per view #146

Open
dalescher opened this issue Nov 10, 2020 · 0 comments
Open

Django cache per view #146

dalescher opened this issue Nov 10, 2020 · 0 comments

Comments

@dalescher
Copy link

dalescher commented Nov 10, 2020

I am trying to use locMemCache to cache some views with Django. When I cache the whole site with the following settings for middleware, everything works as expected, I have both html minification and caching working properly:

MIDDLEWARE = [
    'django.middleware.cache.UpdateCacheMiddleware',
    'htmlmin.middleware.HtmlMinifyMiddleware',
    [...]
    'django.middleware.cache.FetchFromCacheMiddleware',
    'htmlmin.middleware.MarkRequestMiddleware',
]

However, when I try to cache only some specific views, I delete both UpdateCacheMiddleware and FetchFromCacheMiddleware, and use instead the following in urls.py (as per django documentation about cache framework):

from django.views.decorators.cache import cache_page

urlpatterns = [
    path('', cache_page(600)(views.HomePage.as_view()), name='home'),
]

Then, if I do not use htmlmin (HTML_MINIFY = False), caching is working fine. But if I activate htmlmin, caching is not working anymore. I tried to move htmlmin.middleware.HtmlMinifyMiddleware and htmlmin.middleware.MarkRequestMiddleware at different locations in the MIDDLEWARE setting, beginning, end, but without any effect. I also tried to use only one of the two htmlmin middlewares, but then there is no minification.

What am I missing here? Is it possible to use htmlmin with per-view caching?

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

No branches or pull requests

1 participant