I am trying to setup cache with django.
Right now, I just test with LocMemCache, with the following in my settings.py file:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "unique-snowflake"
}
}
Everything works well when I use persite caching, by adding as per doc the following to middleware:
MIDDLEWARE = [
'django.middleware.cache.UpdateCacheMiddleware',
# other middlewares
'django.middleware.cache.FetchFromCacheMiddleware'
]
However, when I try to cache only specific views, I understand that I should not use those middlewares since they are used to cache the whole site, which I do not want.
I then only do the following in my urls.py:
from django.views.decorators.cache import cache_page
urlpatterns = [
path('', cache_page(600)(views.HomePage.as_view()), name='home'),
]
But then, cache does not seem to work (I have the same TTFB that without cache, when I have almost no TTFB when caching the whole site).
What am I missing here?
Thanks in advance for your help!