1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from time import time
class cache(object):
def __init__(self, seconds):
self.seconds = seconds
self.value = None
self.timestamp = None
def __call__(self, f):
def cached():
now = time()
if now - self.seconds > self.timestamp:
self.value = f()
self.timestamp = now
return self.value
return cached
|
More like this
- Run and cache only one instance of a heavy request by farnsworth 2 years, 10 months ago
- per-function cache decorator by nicois 5 years, 4 months ago
- register.tag as a class decorator by gsakkis 3 years, 4 months ago
- template + cache = crazy delicious by jacobian 6 years, 1 month ago
- Custom model field for mysql time type. by xuqingkuang 3 years, 7 months ago
Comments