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