Load cache file and return cached data
760206
def _load_cache(self):
        """"""
        # If the cached file exist, read-it
        max_refresh_date = timedelta(days=7)
        cached_data = {}
        try:
            with open(self.cache_file, 'rb') as f:
                cached_data = pickle.load(f)
        except Exception as e:
            logger.debug("Cannot read version from cache file: {} ({})".format(self.cache_file, e))
        else:
            logger.debug("Read version from cache file")
            if (cached_data['installed_version'] != self.installed_version() or
                    datetime.now() - cached_data['refresh_date'] > max_refresh_date):
                # Reset the cache if:
                # - the installed version is different
                # - the refresh_date is > max_refresh_date
                cached_data = {}
        return cached_data
698641
function cache(item, options) {
    var dir_path = pathutils.join([
        item.conf.cache.base_path,
        pathutils.getHashPath(item.source),
    ]);

    var meta_path = pathutils.join([dir_path, "meta"]);
    var source_path = pathutils.join([dir_path, "source"]);

    if (item.source_type === "file" && !item.conf.cache.copy_source_file) {
        source_path = item.source;
    }

    var target_path = pathutils.join([dir_path, 'targets', pathutils.getOptionsPath(options)]);

    /*
     * lock the files in sequence, not in parallel
     * otherwise a deadlock with other request may occur
     */
    var promise = lock(source_path).then(function(l) {
        logging.debug(item.id, "Locked: source file");
        item.locks.source = l;
        return lock(meta_path);
    }).then(function(l) {
        logging.debug(item.id, "Locked: metadata");
        item.locks.meta = l;
        return lock(target_path);
    }).then(function(l) {
        logging.debug(item.id, "Locked: target file");
        item.locks.target = l;
        return item;
    }).
    then(function(item) {
        return meta_data_still_fresh(item);
    }).
    then(function(item) {
        //meta data is still fresh
        logging.debug(item.id, "Metadata is still fresh");

        return item;
    }, function(item) {
        //meta_data is stale or doesn't exist
        logging.debug(item.id, "Metadata is stale");
        //clear the item directory and download a new version of the source
        var source_promise = fsutils.cleardir(dir_path).
        then(function() {
            logging.debug(item.id, "Item directory cleared");
            logging.debug(item.id, "Requesting source", item.source);
            return source(item);
        }, function(err) {
            // clearing the directory failed.
            // maybe it didn't exists, which would be ok
            if (err.code === "ENOENT") {
                logging.debug(item.id, "Requesting source", item.source);
                return source(item);
            } else {
                //no, it failed for some other reason
                item.error = err;
                throw item;
            }
        }).
        then(function(success) {
            //download succeeded
            logging.debug(item.id, "Source file ready");
            stats.download_success();
            //now only read metadata, don't evaluate headers or else
            //things with max-age=0 will always fail
            return read_meta_data(item);
        }, function(error) {
            logging.debug(item.id, "Acquiring source failed", error);
            stats.download_failure();
            throw item;
        });

        return source_promise;
    }).
    then(function(item) {
        //at this point the item is definitely fresh
        return get_target_file(item);
    }).
    then(function(item) {
        //the target has also been found. all done! \o/
        item.locks.meta();
        logging.debug(item.id, "Released lock: metadata");
        if (typeof item.locks.source === "function") {
            item.locks.source();
            logging.debug(item.id, "Released lock: source file");
        } else {
            //
        }

        register_for_gc(item);
        return item;
    },function(item) {
        item.locks.meta();
        logging.debug(item.id, "Released lock: metadata");
        item.locks.source();
        logging.debug(item.id, "Released lock: source file");
        item.locks.target();
        logging.debug(item.id, "Released lock: target file");

        register_for_gc(item);
        throw item;
    });

    return promise;
}
979478
private function loadCache()
    {
        if (!is_null($this->cache)) {
            return $this->cache;
        }

        if (file_exists($this->getCacheFile()) && !empty($this->getCacheFile())) {
            $this->cache = json_decode(file_get_contents($this->getCacheFile()), true);
            return $this->cache;
        }
        return null;
    }
1065638
def load(self):
        
        try:
            with open(self.file_root + '.pkl', "rb") as f:
                return pickle.load(f)
        except IOError:
            raise CacheMissing(self.file_root)
711557
def _load_cache(self):
        """"""
        if not self._disable_cache and os.path.exists(self._cache_path):
            _LOGGER.debug("Cache found at: %s", self._cache_path)
            loaded_cache = UTILS.load_cache(self._cache_path)

            UTILS.update(self._cache, loaded_cache)

        self._save_cache()
179371
def load_items():
    

    filename = os.path.join(os.path.dirname(__file__), "data", "items.json")

    with open(filename) as f:
        items = json.loads(f.read())["result"]["items"]
        for item in items:
            ITEMS_CACHE[item["id"]] = item
540069
def load_cache():
    
    if not os.path.exists(settings.DUP_FILTER_FILE):
        return set()

    with open(settings.DUP_FILTER_FILE) as f:
        return set(
            json.loads(f.read())
        )
28255
def cache_file(filename, reload_on_change=False, opts=default_opts):
    """"""
    filename = pyc2py(filename)
    if filename in file_cache:
        if reload_on_change: checkcache(filename)
        pass
    else:
        opts['use_linecache_lines'] = True
        update_cache(filename, opts)
        pass
    if filename in file_cache:
        return file_cache[filename].path
    else: return None
    return
1204712
def tryload_cache_list(dpath, fname, cfgstr_list, verbose=False):
    
    data_list = [tryload_cache(dpath, fname, cfgstr, verbose) for cfgstr in cfgstr_list]
    ismiss_list = [data is None for data in data_list]
    return data_list, ismiss_list
1264413
def _load_data(self, reset=False):
        ''' 
        '''

        log = logging.getLogger("%s.%s" % (self.log_name,
                                           inspect.stack()[0][3]))
        log.setLevel(self.log_level)
        for attr, obj in self.datafile_obj.items():
            if reset or obj['latest_mod'] > obj['last_json_mod']:
                conn = obj['conn']
                sparql = "DROP ALL;"
                if os.path.isdir(obj['cache_path']):
                    shutil.rmtree(obj['cache_path'], ignore_errors=True)
                os.makedirs(obj['cache_path'])
                drop_extensions = conn.update_query(sparql)
                rdf_resource_templates = []
                rdf_data = []
                for path, files in obj['files'].items():
                    for file in files:
                        file_path = os.path.join(path, file)
                        # data = open(file_path).read()
                        # log.info(" uploading file: %s | namespace: %s",
                        #          file,
                        #          conn.namespace)
                        # data_type = file.split('.')[-1]
                        result = conn.load_data(file_path,
                                                #datatype=data_type,
                                                graph=str(getattr(NSM.kdr,
                                                                  file)),
                                                is_file=True)
                        if result.status_code > 399:
                            raise ValueError("Cannot load '{}' into {}".format(
                                file_name, conn))
1219187
private <T> T loadDataFromCache(final Class<T> clazz, final Object cacheKey, final long maxTimeInCacheBeforeExpiry) throws CacheLoadingException, CacheCreationException {
        return cacheManager.loadDataFromCache(clazz, cacheKey, maxTimeInCacheBeforeExpiry);
    }
648944
def get_from_cache(url):
    
    # if the tool is configured to use the cache
    if settings.use_cache:
        # determine the filename by hashing the url
        filename = hashlib.md5(url.encode('utf-8')).hexdigest()

        cache_path_filename = os.path.join(settings.cache_folder, os.extsep.join([filename, 'json']))
        # open the cache file for this url hash if it already exists, otherwise
        # return None
        if os.path.isfile(cache_path_filename):
            with io.open(cache_path_filename, encoding='utf-8') as cache_file:
                response_json = json.load(cache_file)
            log('Retrieved response from cache file "{}" for URL "{}"'.format(cache_path_filename, url))
            return response_json
819168
public static void loadCache(Map<String, String> cache, File file, int maxSize) {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line = null;
            while ((line = br.readLine()) != null) {
                int sepIndex = line.indexOf(" ");
                String hash = line.substring(0, sepIndex);
                String urlExternalForm = line.substring(sepIndex + 1);
                cache.put(urlExternalForm, hash);
            }
        } catch (FileNotFoundException e) {
            // Nothing: New cache will be used.
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            FileUtil.closeAndIgnoreExceptions(br);
        }
    }
184256
def _get_cached_response(self):
        """"""

        if not self._is_cached():
            response = self._download_response()
            self.cache.set_xml(self._get_cache_key(), response)

        return self.cache.get_xml(self._get_cache_key())
289105
def retrieve(self, key):
        """"""
        column_file = os.path.join(self._hash_dir, '%s.json' % key)
        cache_file = os.path.join(self._hash_dir, '%s.npy' % key)

        if os.path.exists(cache_file):
            data = np.load(cache_file)
            if os.path.exists(column_file):
                with open(column_file, 'r') as json_file:
                    columns = json.load(json_file)
                data = pd.DataFrame(data, columns=columns)
        else:
            return None

        return data
597852
public function loadCacheDetails()
    {
        $cacheFile = md5($this->url);
        $this->fileName = $this->saveFolder . $cacheFile;
        $this->fileJson = $this->fileName . ".json";
        if (is_readable($this->fileJson)) {
            $this->cache = json_decode(file_get_contents($this->fileJson), true);
        }
    }
1312642
function loadUncached () {
    // execute original query
    return this.query.executeQuery()
    // cache result
    .then(results => {
        // cache results if there are any
        if (results.length > 0) {
            // cache results - do not wait to complete
            this.cacheResults(results)
        }
        // resolve with results
        return results
    })
}