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