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 5 years, 6 months ago
  2. Conditional cache decorator by alexisbellido 1 year, 8 months ago
  3. per-function cache decorator by nicois 6 years, 3 months ago
  4. Caching Decorator by spenczar 1 year, 12 months ago
  5. Cache decorator by xyb 6 years, 4 months ago

Comments

(Forgotten your password?)