Hi *,

I always find myself using this idiom:

cache.get(key, set_cached(key, KeyValue.objects.get(user=request.user, 
key=key)))

Which basically sets the key upon fetching it. It requires me to define
set_cached to be something like this though:

def set_cached(key, value):
        """ Functional version of cache.set which returns the value """
        cache.set(key, value, 300)
        return value

It would be nice if cache.set returned the value by default, or even better
if something like this existed:

cache.get_and_set(key, default)

Which would set the key to the default and return the default if the key isn't
in the cache, or return the value if it is.

Chris.

-------------------
http://mccormick.cx

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to