I would like to cache some view until end of month.
e.g.
@cache_page_expire_at_end_of_month
def some_view(request):
...
I found this old question Django per-view caching: set expiry time rather than cache timeout? But I can't get it to work.
I would like to cache some view until end of month.
e.g.
@cache_page_expire_at_end_of_month
def some_view(request):
...
I found this old question Django per-view caching: set expiry time rather than cache timeout? But I can't get it to work.
To cache a Django view until the end of the month, you need to create a custom decorator that calculates the remaining time until the end of the current month and then uses Django's caching mechanism with that specific timeout. Django does not have a built-in decorator for setting cache expiration to the end of the month, so you'll have to implement this functionality yourself.
Here’s a step-by-step guide on how to do it:
from django.utils.decorators import method_decorator
To apply this decorator to a class-based view, you'll need to use the method_decorator like this: