server/sources/__init__.py
changeset 5655 ef903fff826d
parent 5557 1a534c596bff
parent 5642 6a90357b9769
child 5821 656c974961c4
equal deleted inserted replaced
5654:8bb34548be86 5655:ef903fff826d
    50             print '  -->', results
    50             print '  -->', results
    51     # return true so it can be used as assertion (and so be killed by python -O)
    51     # return true so it can be used as assertion (and so be killed by python -O)
    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, ttl):
    56         # time to live in minutes
    56         # time to live in seconds
    57         self.ttl = timedelta(0, ttlm*60 + ttls, 0)
    57         if ttl <= 0:
       
    58             raise ValueError('TimedCache initialized with a ttl of %ss' % self.ttl.seconds)
       
    59         self.ttl = timedelta(seconds=ttl)
    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):