From aaed54f1dcdd08dc7ba4514ef029bb676364377d Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 29 Nov 2007 16:43:02 +0000 Subject: [PATCH] added cache delete. updated some logging git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1151 9efc2488-bf62-4759-914b-345cdb29e865 --- src/python/osrf/cache.py | 18 ++++++++++++++---- src/python/osrf/net.py | 4 +--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/python/osrf/cache.py b/src/python/osrf/cache.py index b34309d..60419ad 100644 --- a/src/python/osrf/cache.py +++ b/src/python/osrf/cache.py @@ -1,5 +1,6 @@ import memcache from osrf.json import osrfObjectToJSON, osrfJSONToObject +from osrf.log import * ''' Abstracted OpenSRF caching interface. @@ -23,7 +24,7 @@ class CacheClient(object): ''' global _client if servers: - self.client = memcache.Client(server, debug=0) + self.client = memcache.Client(server, debug=1) else: if not _client: raise CacheException("not connected to any memcache servers. try CacheClient.connect(servers)") @@ -33,14 +34,23 @@ class CacheClient(object): global defaultTimeout if timeout is None: timeout = defaultTimeout - self.client.set(key, osrfObjectToJSON(val), timeout) + s = osrfObjectToJSON(val) + osrfLogInternal("cache: %s => %s" % (str(key), s)) + return self.client.set(str(key), s, timeout) def get(self, key): - return osrfJSONToObject(self.client.get(key) or "null") + o = self.client.get(str(key)) + osrfLogInternal("cache: fetching %s => %s" % (str(key), o)) + return osrfJSONToObject(o or "null") + + def delete(self, key): + osrfLogInternal("cache: deleting %s" % str(key)) + self.client.delete(str(key)) @staticmethod def connect(svrs): global _client - _client = memcache.Client(svrs, debug=0) + osrfLogDebug("cache: connecting to servers %s" % str(svrs)) + _client = memcache.Client(svrs, debug=1) diff --git a/src/python/osrf/net.py b/src/python/osrf/net.py index f04efa0..5dc58ab 100644 --- a/src/python/osrf/net.py +++ b/src/python/osrf/net.py @@ -131,12 +131,10 @@ class osrfNetwork(JabberClient): if len(self.queue) == 0: while timeout >= 0 and len(self.queue) == 0: starttime = time.time() - osrfLogInternal("going into stream loop at " + str(starttime)) act = self.get_stream().loop_iter(timeout) endtime = time.time() - starttime timeout -= endtime - osrfLogInternal("exiting stream loop after %s seconds" % str(endtime)) - osrfLogInternal("act = %s : queue length = %d" % (act, len(self.queue)) ) + osrfLogInternal("exiting stream loop after %s seconds. act=%s, queue size=%d" % (str(endtime),act, len(self.queue))) if not act: self.idle() # if we've acquired a message, handle it -- 2.11.0