cache.set(key, timeout=0)

22 views
Skip to first unread message

Thomas Güttler

unread,
Feb 10, 2015, 3:52:50 AM2/10/15
to Django Users
I want the cache timeout to be configurable:

- N --> number of seconds
- None --> cache for every
- 0 --> do not cache at all.

I am not sure if timeout=0 really does what I want.

I could not find it explicitly in the docs: https://docs.djangoproject.com/en/1.7/topics/cache/#basic-usage

I don't want to put a lot of "if default_cache_timeout==0: ...." into my code.

It would be nice if django would support this. This would make my code simpler.

Does cache.set(key, timeout=0) do no caching at all?

If yes, shouldn't this be stated in the docs explicitly?

Regards,
Thomas Güttler

--
Thomas Güttler
http://thomas-guettler.de/

Russell Keith-Magee

unread,
Feb 10, 2015, 10:35:15 PM2/10/15
to Django Users
Hi Thomas,

You are correct - if you set timeout=0, the cached value immediately expire (effectively "don't cache"). 

This appears to be an oversight of the documentation; the section you reference includes a discussion of the None value, but not the 0 value - a clarification would definitely be worthwhile. 

If you open this as a ticket, we can make sure your suggestion isn't forgotten. It would also be a very easy contribution to make - the patch would be a very simple one

Yours
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54D9C6A3.9030506%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages