from __future__ import with_statement
import time
import threading
+import pickle
from datetime import datetime
# maximum lifetime of cached data (in seconds)
def get_data(self):
return self.data
+ def __getstate__(self):
+ d = dict(self.__dict__)
+ del d['lock']
+ return d
+
+ def __setstate__(self, d):
+ self.__dict__.update(d)
+ self.lock = threading.RLock()
+
+
class Cache:
cache = {}
if not data or data.is_expired():
return None
return data.get_data()
+
+ def save_to_file(self, filename):
+ f = open(filename, 'w')
+ pickle.dump(self.cache, f)
+
+ def load_from_file(self, filename):
+ f = open(filename, 'r')
+ self.cache = pickle.load(f)