equal
deleted
inserted
replaced
63 if ttl <= 0: |
63 if ttl <= 0: |
64 raise ValueError('TimedCache initialized with a ttl of %ss' % ttl.seconds) |
64 raise ValueError('TimedCache initialized with a ttl of %ss' % ttl.seconds) |
65 self.ttl = timedelta(seconds=ttl) |
65 self.ttl = timedelta(seconds=ttl) |
66 |
66 |
67 def __setitem__(self, key, value): |
67 def __setitem__(self, key, value): |
68 dict.__setitem__(self, key, (datetime.now(), value)) |
68 dict.__setitem__(self, key, (datetime.utcnow(), value)) |
69 |
69 |
70 def __getitem__(self, key): |
70 def __getitem__(self, key): |
71 return dict.__getitem__(self, key)[1] |
71 return dict.__getitem__(self, key)[1] |
72 |
72 |
73 def clear_expired(self): |
73 def clear_expired(self): |
74 now_ = datetime.now() |
74 now_ = datetime.utcnow() |
75 ttl = self.ttl |
75 ttl = self.ttl |
76 for key, (timestamp, value) in self.items(): |
76 for key, (timestamp, value) in self.items(): |
77 if now_ - timestamp > ttl: |
77 if now_ - timestamp > ttl: |
78 del self[key] |
78 del self[key] |
79 |
79 |