Beispiel #1
0
 def saveIfStale(self):
     now = time.time()
     if now - self.saveTime_ > self.saveTimeout_:
         try:
             self.save()
         except:
             logger.exception("non-fatal error: Could not save cahced data to %s" % self.path_)
             return
         self.saveTime_ = now
Beispiel #2
0
 def __init__(self, classToWrap, path, saveTimeout, **kwargs):
     self.saveTimeout_ = saveTimeout
     self.path_ = path
     self.instance_ = None
     if os.path.exists(path):
         try:
             f = file(path, "r")
             self.instance_ = cPickle.loads(f.read())
             f.close()
             self.saveTime_ = time.time()
         except:
             logger.exception("Could not load cached data from %s" % path)
     if not self.instance_:
         self.instance_ = classToWrap(**kwargs)
         self.saveTime_ = 0
     else:
         self.instance_.init(**kwargs)
     self.lock_ = dsthread.ReadWriteLock(threading.RLock)