From: Tony Mack Date: Thu, 26 May 2011 19:43:24 +0000 (-0400) Subject: more misc methods X-Git-Tag: sfa-1.0-22~5 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d0c918cfda1e393cb0f7b20569c3df57808d6058;p=sfa.git more misc methods --- diff --git a/sfa/util/cache.py b/sfa/util/cache.py index daaf443e..fcea588a 100644 --- a/sfa/util/cache.py +++ b/sfa/util/cache.py @@ -6,6 +6,7 @@ import time import threading import pickle from datetime import datetime +from pprint import pprint # maximum lifetime of cached data (in seconds) MAX_CACHE_TTL = 60 * 60 @@ -44,6 +45,16 @@ class CacheData: def get_data(self): return self.data + + def dump(self): + return self.__dict__ + + def __str__(self): + return str(self.dump()) + + def tostring(self): + return self.__str__() + def __getstate__(self): d = dict(self.__dict__) del d['lock'] @@ -72,6 +83,18 @@ class Cache: return None return data.get_data() + def dump(self): + result = {} + for key in self.cache: + result[key] = self.cache[key].__getstate__() + return result + + def __str__(self): + return str(self.dump()) + + def tostring(self): + return self.__str() + def save_to_file(self, filename): f = open(filename, 'w') pickle.dump(self.cache, f)