2 from osrf.json import osrfObjectToJSON, osrfJSONToObject
5 Abstracted OpenSRF caching interface.
6 Requires memcache: ftp://ftp.tummy.com/pub/python-memcached/
12 class CacheException(Exception):
13 def __init__(self, info):
16 return "%s: %s" % (self.__class__.__name__, self.info)
18 class CacheClient(object):
19 def __init__(self, servers=None):
20 ''' If no servers are provided, this instance will use
21 the global memcache connection.
22 servers takes the form ['server:port', 'server2:port2', ...]
26 self.client = memcache.Client(server, debug=0)
29 raise CacheException("not connected to any memcache servers. try CacheClient.connect(servers)")
32 def put(self, key, val, timeout=None):
35 timeout = defaultTimeout
36 self.client.set(key, osrfObjectToJSON(val), timeout)
39 return osrfJSONToObject(self.client.get(key) or "null")
44 _client = memcache.Client(svrs, debug=0)