Hi everyone,
While working on Django projects, I noticed that implementing proper cache control on views, especially for sensitive content like login pages or user-specific data, can be a bit cumbersome. While the @never_cache
decorator is a great tool for views, I was wondering if Django could benefit from a built-in solution.
For example:
- A built-in CacheControlMixin:
A mixin that could handle cache control settings out-of-the-box for class-based views. It could accept configurable attributes for cache directives, making it more versatile. - Cache Control Middleware:
Middleware that enforces global cache control rules, with the ability to exclude specific views (similar to thelogin_not_required
attribute in the newLoginRequiredMiddleware
). - Integration with Django settings:
Adding cache control settings directly tosettings.py
could make it easier to enforce default rules in the application, while still allowing fine-grained control at the view level.
What are your thoughts on introducing one of these solutions (or a similar approach) into Django core? I’d love to hear the community’s thoughts and see if others have encountered similar challenges.
I look forward to your feedback and ideas!
Best regards,
Matteo