server/sources/__init__.py
branchstable
changeset 5637 b72a838aa109
parent 5424 8ecbcbff9777
child 5642 6a90357b9769
equal deleted inserted replaced
5605:2604545d7dd9 5637:b72a838aa109
    52     return True
    52     return True
    53 
    53 
    54 class TimedCache(dict):
    54 class TimedCache(dict):
    55     def __init__(self, ttlm, ttls=0):
    55     def __init__(self, ttlm, ttls=0):
    56         # time to live in minutes
    56         # time to live in minutes
    57         self.ttl = timedelta(0, ttlm*60 + ttls, 0)
    57         self.ttl = timedelta(seconds=ttlm*60 + ttls)
       
    58         if self.ttl.seconds <= 0:
       
    59             raise ValueError('TimedCache initialized with a ttl of %ss' % self.ttl.seconds)
    58 
    60 
    59     def __setitem__(self, key, value):
    61     def __setitem__(self, key, value):
    60         dict.__setitem__(self, key, (datetime.now(), value))
    62         dict.__setitem__(self, key, (datetime.now(), value))
    61 
    63 
    62     def __getitem__(self, key):
    64     def __getitem__(self, key):