Login

Cache Decorator

Author:
ericmoritz
Posted:
December 9, 2008
Language:
Python
Version:
1.0
Tags:
caching
Score:
4 (after 4 ratings)

A cache decorator.

1
2
3
4
5
6
7
8
def cache_result(callable, cache_key, timeout):
    def inner(*args, **kwargs):
       result = cache.get(cache_key)
       if result is None:
           result = callable(*args, **kwargs)
           cache.set(cache_key, result, timeout)
       return result
    return inner

More like this

  1. Stales Cache Class Method Decorator by amitu 6 years, 8 months ago
  2. Conditional cache decorator by alexisbellido 2 years, 10 months ago
  3. per-function cache decorator by nicois 7 years, 5 months ago
  4. Caching Decorator by spenczar 3 years, 2 months ago
  5. Cache decorator by xyb 7 years, 7 months ago

Comments

Please login first before commenting.