{{{
from pathlib import Path
from django.conf import settings
from django.core.cache import caches
default_cache = caches[settings.CACHE_MIDDLEWARE_ALIAS]
cache_key = ".".join(Path(request.path[1:]).parts)
if not (response := default_cache.get(cache_key)):
response = view_func(request, *args, **kwargs)
response.add_post_render_callback(
lambda r: default_cache.set(cache_key, r, timeout)
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34271>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Ahter Sönmez (added)
* status: new => closed
* resolution: => duplicate
Comment:
I think this is related to #5815 - per-view cache invalidation.
The issue there is it's ''Not Easy™'' to generate the right cache key
outside of the request context.
9 time 10 I've wanted to just clear by the path as suggested here.
Can you think about whether we can make the make key function more
pluggable and so solve #5815 in a way compatible with your desire here?
I'm going to provisionally mark this as a duplicate. If on investigation
that's not right, do re-open and I'll take a further look.
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34271#comment:1>