Along the lines of get_or_create(), does it make sense to implement a
get_or_set() function for quick caches?
It can be used in this way:
from django.core.cache import cache
...
big_list = cache.get_or_set('big_list', lambda: BigItems.objects.all(),
60 * 60)
to retrieve from cache or, if not in the cache, to cache the data for one
hour in just one line of code.
Implement this in django.core.cache.backends.base as
def get_or_set(self, key, value_function, timeout=None):
_cached = cache.get(key)
if not _cached:
_cached = value_function()
cache.set(key, _cached, timeout)
return _cached
It looks a little funny with the lambda function, but I think it would be
useful. What do you think?
Thanks,
j
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---