-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemcached2.py
More file actions
29 lines (23 loc) · 781 Bytes
/
memcached2.py
File metadata and controls
29 lines (23 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Memcached(object):
def __init__(self, reactor=None):
if reactor is None:
from twisted.internet import reactor
self.reactor = reactor
self.store = {}
self.timeouts = {}
def get(self, key):
return self.store[key]
def set(self, key, value, flags, timeout=0):
self.cancelTimeout(key)
self.store[key] = (value, flags)
if timeout > 0:
timeoutCall = self.reactor.callLater(timeout, self.delete, key)
self.timeouts[key] = timeoutCall
return key
def delete(self, key):
self.cancelTimeout(key)
del self.store[key]
def cancelTimeout(self, key):
dc = self.timeouts.get(key)
if dc and dc.active():
dc.cancel()