def load(self): """ Load caches from specified file """ # Nothing to do when persistent caching is off if not self._filename or get_cache_level() < config.CACHE_PERSISTENT: return # Load the saved cache from file try: log.debug("Loading persistent cache from {0}".format( self._filename)) input_file = gzip.open(self._filename, 'rb') data = pickle.load(input_file) input_file.close() except EOFError: log.cache("Cache file empty, will fill it upon exit") return except (IOError, zlib.error), error: if getattr(error, "errno", None) == 2: log.warn("Cache file not found, will create one on exit") return else: log.error("Failed to load the cache ({0})".format(error)) log.warn("Going on but switching to the CACHE_OBJECTS level") set_cache_level(config.CACHE_OBJECTS) self.unlock() return
def load(self): """ Load caches from specified file """ # Nothing to do when persistent caching is off if not self._filename or get_cache_level() < config.CACHE_PERSISTENT: return # Load the saved cache from file try: log.debug("Loading persistent cache from {0}".format( self._filename)) input_file = gzip.open(self._filename, 'rb') data = pickle.load(input_file) input_file.close() except EOFError: log.cache("Cache file empty, will fill it upon exit") return except (IOError, zlib.error) as error: if getattr(error, "errno", None) == 2: log.warn("Cache file not found, will create one on exit") return else: log.error("Failed to load the cache ({0})".format(error)) log.warn("Going on but switching to the CACHE_OBJECTS level") set_cache_level(config.CACHE_OBJECTS) self.unlock() return # Restore cache for immutable & mutable classes first for current_class in self._immutable + self._mutable: try: log.cache("Loading cache for {0}".format( current_class.__name__)) current_class._cache = data[current_class.__name__] except KeyError: log.cache("Failed to load cache for {0}, starting " "with empty".format(current_class.__name__)) current_class._cache = {} # Containers to be loaded last (to prevent object duplicates) for current_class in self._containers: try: log.cache("Loading cache for {0}".format( current_class.__name__)) current_class._cache = data[current_class.__name__] except KeyError: log.cache("Failed to load cache for {0}, starting " "with empty".format(current_class.__name__)) current_class._cache = {} # Wake up container objects from the id-sleep for container in current_class._cache.values(): container._wake() # Clear expired items and give a short summary for debugging self.expire() log.cache("Cache restore stats:\n" + self.stats().strip())
def load(self): """ Load caches from specified file """ # Nothing to do when persistent caching is off if not self._filename or get_cache_level() < config.CACHE_PERSISTENT: return # Load the saved cache from file try: log.debug("Loading persistent cache from {0}".format( self._filename)) input_file = gzip.open(self._filename, 'rb') data = pickle.load(input_file) input_file.close() except EOFError: log.cache("Cache file empty, will fill it upon exit") return except (IOError, zlib.error) as error: if getattr(error, "errno", None) == 2: log.warn("Cache file not found, will create one on exit") return else: log.error("Failed to load the cache ({0})".format(error)) log.warn("Going on but switching to the CACHE_OBJECTS level") set_cache_level(config.CACHE_OBJECTS) self.unlock() return # Restore cache for immutable & mutable classes first for current_class in self._immutable + self._mutable: try: log.cache("Loading cache for {0}".format( current_class.__name__)) current_class._cache = data[current_class.__name__] except KeyError: log.cache("Failed to load cache for {0}, starting " "with empty".format(current_class.__name__)) current_class._cache = {} # Containers to be loaded last (to prevent object duplicates) for current_class in self._containers: try: log.cache("Loading cache for {0}".format( current_class.__name__)) current_class._cache = data[current_class.__name__] except KeyError: log.cache("Failed to load cache for {0}, starting " "with empty".format(current_class.__name__)) current_class._cache = {} # Wake up container objects from the id-sleep for container in current_class._cache.itervalues(): container._wake() # Clear expired items and give a short summary for debugging self.expire() log.cache("Cache restore stats:\n" + self.stats().strip())