Richard
Richard

Reputation: 65600

Django per-view caching: set expiry time rather than cache timeout?

I'm using Django caching with memcached and I want to use per-view caching.

However I'd like to know if I can set an expiry time for the page (e.g. 4am today EST) rather than the cache timeout in seconds.

If I want the page to stay cached for 15 minutes, then I just do this:

@cache_page(60 * 15)

But how do I say "cache this page until tomorrow at 4am EST"?

Upvotes: 3

Views: 956

Answers (1)

dm03514
dm03514

Reputation: 55972

I don't know if there is a nice built in way to do it, but if not you could create your own decorator that would essential do the same thing as cache_page

But you could give your decorator a time string and inside of it, you could calculate the number of seconds until that time, then just call the original cache function, with the seconds until the time you specified

Upvotes: 3

Related Questions