Check if cached file exists, and if so, return it
979218
function returnFile(cb) {
			fs.readFile(fileToLoad, function (err, fileBuf) {
				if (err || ! fileBuf) {
					createFile(function (err) {
						if (err) return cb(err);
						returnFile(cb);
					});
					return;
				}
				cb(null, fileBuf, fileToLoad);
			});
		}
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
303971
function exists(filepath) {
  const cached = existsCache.has(filepath);

  // Only return positive to allow for generated files
  if (cached) return true;

  const filepathExists = fs.existsSync(filepath);

  if (filepathExists) existsCache.add(filepath);

  return filepathExists;
}
402652
def cached_unless_authenticated(timeout=50, key_prefix='default'):
    """"""
    def caching(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            cache_fun = current_cache.cached(
                timeout=timeout, key_prefix=key_prefix,
                unless=lambda: current_cache_ext.is_authenticated_callback())
            return cache_fun(f)(*args, **kwargs)
        return wrapper
    return caching
389428
def check_existance(f):
    """"""
    if not opath.isfile(f):
        logging.error("Nanoget: File provided doesn't exist or the path is incorrect: {}".format(f))
        sys.exit("File provided doesn't exist or the path is incorrect: {}".format(f))
854788
def has_changed (filename):
    """"""
    key = os.path.abspath(filename)
    mtime = get_mtime(key)
    if key not in _mtime_cache:
        _mtime_cache[key] = mtime
        return True
    return mtime > _mtime_cache[key]
50079
def check_cache(path):
    
    if not os.path.exists(path):
        return True
    else:
        # check the age
        mod_date = datetime.fromtimestamp(os.path.getmtime(path))
        if mod_date < (datetime.now() - timedelta(days=30)):
            return True
        else:
            return False
1126758
async function _handleFileInCache(filename, cache) {
  if (cache.get(filename) !== true) return cache.get(filename);
  return _addReadCallback(filename);
}
1046187
def get_cached(self, path, cache_name, **kwargs):
        
        if gw2api.cache_dir and gw2api.cache_time and cache_name:
            cache_file = os.path.join(gw2api.cache_dir, cache_name)
            if mtime(cache_file) >= time.time() - gw2api.cache_time:
                with open(cache_file, "r") as fp:
                    tmp = json.load(fp)
                return self.make_response(tmp["data"], tmp["meta"])
        else:
            cache_file = None

        meta, data = self._get(path, **kwargs)

        if cache_file:
            with open(cache_file, "w") as fp:
                json.dump({"meta": meta, "data": data}, fp, indent=2)

        return self.make_response(data, meta)
883911
def tryload_cache(dpath, fname, cfgstr, verbose=None):
    
    try:
        return load_cache(dpath, fname, cfgstr, verbose=verbose)
    except IOError:
        return None
323400
def _is_cache_dir_appropriate(cache_dir, cache_file):
    
    if os.path.exists(cache_dir):
        files = os.listdir(cache_dir)
        if cache_file in files:
            return True
        return not bool(files)
    return True
713433
function(key, fn) {
    var self = this;
    var filepath = this._makeFilepath(key);

    fs.exists(filepath, function(exists) {
      if (!exists) {
        return fn();
      }

      fs.readFile(filepath, 'UTF8', function(err, data) {
        if (err) {
          return fn(err);
        }

        var cache = JSON.parse(data);

        if (!self._cacheIsValid(cache)) {
          return self.del(key, fn);
        }
        fn(null, cache.data);
      });

    });
  }
869648
function isCached()
    {
        $file = $this->cache_dir . '/' . base64_encode($_SERVER['REQUEST_URI']) . '.html';
        if (!file_exists($file))
        {
            return false;
        }
        elseif (filemtime($file) + $this->expire < time())
        {
            return false;
        }
        else
        {
            return true;
        }
    }
66490
def get_cached(path, cache_name=None, **kwargs):
    
    if gw2api.cache_dir and gw2api.cache_time and cache_name is not False:
        if cache_name is None:
            cache_name = path
        cache_file = os.path.join(gw2api.cache_dir, cache_name)
        if mtime(cache_file) >= time.time() - gw2api.cache_time:
            with open(cache_file, "r") as fp:
                return json.load(fp)
    else:
        cache_file = None

    r = gw2api.session.get(gw2api.BASE_URL + path, **kwargs)

    if not r.ok:
        try:
            response = r.json()
        except ValueError:  # pragma: no cover
            response = None
        if isinstance(response, dict) and "text" in response:
            r.reason = response["text"]

    r.raise_for_status()
    data = r.json()

    if cache_file:
        with open(cache_file, "w") as fp:
            json.dump(data, fp, indent=2)

    return data
1213920
def _exists(self, key):
        
        filecache, keycache = self._fileslist()
        msg = keycache.get(key, None)
        if msg:
            path = msg.filename
            meta = filecache[path]
            return path, meta["hostname"], meta.get("flags", "")
        raise KeyError("not found %s" % key)
115448
def ensure_exists(self):
        """"""
        if not cache.exists(self.config):
            logger.debug("Wily cache not found, creating.")
            cache.create(self.config)
            logger.debug("Created wily cache")
        else:
            logger.debug(f"Cache {self.config.cache_path} exists")
727962
def do_files_exist(filenames):
  """"""
  preexisting = [tf.io.gfile.exists(f) for f in filenames]
  return any(preexisting)