]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/memcached.py
6 from .misc
import Object
8 class Memcached(Object
):
10 self
._connection
= memcache
.Client(["localhost"], debug
=1)
12 def get(self
, key
, *args
, **kwargs
):
13 key
= self
._sanitize
_key
(key
)
15 logging
.debug("Retrieving %s from cache..." % key
)
17 ret
= self
._connection
.get(key
, *args
, **kwargs
)
20 logging
.debug("Found nothing for %s" % key
)
22 logging
.debug("Found object for %s" % key
)
26 def get_multi(self
, keys
, *args
, **kwargs
):
27 keys
= (self
._sanitize
_key
(key
) for key
in keys
)
29 logging
.debug("Retrieving keys from cache: %s" % keys
)
31 ret
= self
._connection
.get_multi(keys
, *args
, **kwargs
)
34 logging
.debug("Found nothing for %s" % keys
)
36 logging
.debug("Found objects for %s" % keys
)
40 def add(self
, key
, data
, *args
, **kwargs
):
41 key
= self
._sanitize
_key
(key
)
44 logging
.debug("Putting nothing into cache for %s" % key
)
46 logging
.debug("Putting object into cache for %s" % key
)
48 return self
._connection
.add(key
, data
, *args
, **kwargs
)
50 def set(self
, key
, data
, *args
, **kwargs
):
51 key
= self
._sanitize
_key
(key
)
54 logging
.debug("Putting nothing into cache for %s" % key
)
56 logging
.debug("Putting object into cache for %s" % key
)
58 return self
._connection
.set(key
, data
, *args
, **kwargs
)
60 def delete(self
, key
, *args
, **kwargs
):
61 key
= self
._sanitize
_key
(key
)
63 return self
._connection
.delete(key
, *args
, **kwargs
)
66 key
= self
._sanitize
_key
(key
)
68 logging
.debug("Incrementing key %s" % key
)
70 return self
._connection
.incr(key
)
73 def _sanitize_key(key
):
74 # Memcache does not seem to like any spaces
75 return key
.replace(" ", "-")