def __initializeCache(self, dataHandler, cacheHandler): """ Check if the cache is outdated and, if necessary, compose it using passed datahandler and cacheHandler. If cacheHandler was specified as None, default on-disk JSON handler is used. """ if cacheHandler is None: cacheHandler = JsonCacheHandler(os.path.join(self.__path, "cache"), self.__name, self._logger) self._cacheHandler = cacheHandler # Compare fingerprints from data and cache cacheFp = cacheHandler.getFingerprint() dataVersion = dataHandler.getVersion() currentFp = "{}_{}_{}".format(self.name, dataVersion, eosVersion) # If data version is corrupt or fingerprints mismatch, # update cache if dataVersion is None or cacheFp != currentFp: if dataVersion is None: msg = "data version is None, updating cache" else: msg = 'fingerprint mismatch: cache "{}", data "{}", updating cache'.format(cacheFp, currentFp) self._logger.info(msg) # Generate cache, apply customizations and write it cacheData = CacheGenerator(self._logger).run(dataHandler) CacheCustomizer().runBuiltIn(cacheData) cacheHandler.updateCache(cacheData, currentFp)
def __initializeCache(self, dataHandler, cacheHandler): """ Check if the cache is outdated and, if necessary, compose it using passed datahandler and cacheHandler. If cacheHandler was specified as None, default on-disk JSON handler is used. """ if cacheHandler is None: cacheHandler = JsonCacheHandler(os.path.join(self.__path, 'cache'), self.__name, self._logger) self._cacheHandler = cacheHandler # Compare fingerprints from data and cache cacheFp = cacheHandler.getFingerprint() dataVersion = dataHandler.getVersion() currentFp = '{}_{}_{}'.format(self.name, dataVersion, eosVersion) # If data version is corrupt or fingerprints mismatch, # update cache if dataVersion is None or cacheFp != currentFp: if dataVersion is None: msg = 'data version is None, updating cache' else: msg = 'fingerprint mismatch: cache "{}", data "{}", updating cache'.format( cacheFp, currentFp) self._logger.info(msg) # Generate cache, apply customizations and write it cacheData = CacheGenerator(self._logger).run(dataHandler) CacheCustomizer().runBuiltIn(cacheData) cacheHandler.updateCache(cacheData, currentFp)
def __initializeData(self, dataHandler): """ Using passed dataHandler, compose on-disk cache if necessary, load this cache in memory and return cache handler which deals with it. """ cacheHandler = JsonCacheHandler(os.path.join(self.__path, 'cache'), self.name, self._logger) # Compare fingerprints from data and cache cacheFp = cacheHandler.getFingerprint() dataVersion = dataHandler.getVersion() currentFp = '{}_{}_{}'.format(self.name, dataVersion, eosVersion) # If data version is corrupt or fingerprints mismatch, # update cache if dataVersion is None or cacheFp != currentFp: if dataVersion is None: msg = 'data version is None, updating cache' else: msg = 'fingerprint mismatch: cache "{}", data "{}", updating cache'.format(cacheFp, currentFp) self._logger.info(msg) # Generate cache, apply customizations and write it cacheData = CacheGenerator(self._logger).run(dataHandler) CacheCustomizer().runBuiltIn(cacheData) cacheHandler.updateCache(cacheData, currentFp) return cacheHandler