On 5/23/06, Elver Loho <[EMAIL PROTECTED]> wrote: > Does Django offer any decorators for caching the output of any > function, such as get_latest_books, based on the arguments passed to > it?
Hi Elver, There's no specific cache decorator, but the low-level cache API is so simple to use that doing this would be easy: from django.core.cache import cache num_books = 7 cache_key = 'get_latest_books_%s' % num_books val = cache.get(cache_key) if val is None: # Wasn't found in cache, so do the lookup. val = get_latest_books(days=7) cache.set(cache_key, val, 60) # Save in cache for 60 seconds. return val See http://www.djangoproject.com/documentation/cache/#the-low-level-cache-api for documentation. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---