Copy a file into the cache
483762
public function copyFrom($file, $source)
    {
        if ($this->enabled) {
            $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
            $this->filesystem->ensureDirectoryExists(dirname($this->root . $file));

            if ($this->io->isDebug()) {
                $this->io->writeError('Writing '.$this->root . $file.' into cache');
            }

            return copy($source, $this->root . $file);
        }

        return false;
    }
1029640
def _create_cache_key(source_file):
        
        path, name = os.path.split(source_file)
        return name + str(hash(path))
325476
def _write_cache(self, lines, append=False):
        """"""
        mode = 'at' if append else 'wt'
        with open(self.filepath, mode, encoding='utf8') as fh:
            fh.writelines(line + '\n' for line in lines)
643384
public void cacheFile() {
		if (orientation == Orientation.INV)
			cache = new String[fields][elements];
		else
			cache = new String[elements][fields];
		int x = 0, y = 0;
		Scanner file = null;
		try {
			file = new Scanner(csvFile);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String line;
		StringTokenizer tokenizer;
		while(file.hasNextLine()){
			line = file.nextLine();
			tokenizer = new StringTokenizer(line, ",");
			while(tokenizer.hasMoreTokens()){
				cache[y][x] = tokenizer.nextToken();
				x++;
			}
			x = 0;
			y++;
			
		}
		file.close();
		cached = true;
	}
705431
function _readFileOnEnd(filename, contents, cache) {
  loading--;
  const data = Buffer.concat(contents);
  cache.set(filename, data);
  _fireReadFileCallbacks(filename, data);
  _runFileQueue();
}
1009450
function(src) {
    var cache;

    try {
      cache = fs.existsSync(src) ? file.readJSON(src) : undefined;
    } catch (e) {
      debug(e);
    }

    // Progressively upgrade `cache`, which is one of:
    // empty
    // {}
    // { file: size [,...] }
    // { "": { tips: { label: SHA1, ... } }, label: { file: size, ... }, ... }
    // { "": { version: 0.4, tips: { label: SHA1, ... } },
    //   label: { file: { "": size, compressor: size, ... }, ... }, ... }
    if (typeof cache !== "object") {
      cache = undefined;
    }
    if (!cache || !cache[""]) {
      // If promoting cache to dictionary, assume that data are for last run
      cache = _.zipObject(["", lastrun], [{ version: 0, tips: {} }, cache]);
    }
    if (!cache[""].version) {
      cache[""].version = 0.4;
      _.forEach(cache, function(sizes, label) {
        if (!label || !sizes) {
          return;
        }

        // If promoting sizes to dictionary, assume that compressed size data are indicated by suffixes
        Object.keys(sizes)
          .sort()
          .forEach(function(file) {
            var parts = file.split("."),
              prefix = parts.shift();

            // Append compressed size data to a matching prefix
            while (parts.length) {
              if (typeof sizes[prefix] === "object") {
                sizes[prefix][parts.join(".")] = sizes[file];
                delete sizes[file];
                return;
              }
              prefix += "." + parts.shift();
            }

            // Store uncompressed size data
            sizes[file] = { "": sizes[file] };
          });
      });
    }

    return cache;
  }
515779
def __cache(self, file, content, document):
        

        self.__files_cache.add_content(**{file: CacheData(content=content, document=document)})
572642
def update_cache(filename, opts=default_opts, module_globals=None):
    """"""

    if not filename: return None

    orig_filename = filename
    filename = pyc2py(filename)
    if filename in file_cache: del file_cache[filename]
    path = os.path.abspath(filename)
    stat = None
    if get_option('use_linecache_lines', opts):
        fname_list = [filename]
        mapped_path = file2file_remap.get(path)
        if mapped_path:
            fname_list.append(mapped_path)
            for filename in fname_list:
                try:
                    stat = os.stat(filename)
                    plain_lines = linecache.getlines(filename)
                    trailing_nl = has_trailing_nl(plain_lines[-1])
                    lines = {
                        'plain'   : plain_lines,
                        }
                    file_cache[filename] = LineCacheInfo(stat, None, lines,
                                                         path, None)
                except:
                    pass
                pass
            if orig_filename != filename:
                file2file_remap[orig_filename] = filename
                file2file_remap[os.path.abspath(orig_filename)] = filename
                pass
            file2file_remap[path] = filename
            return filename
        pass
    pass

    if os.path.exists(path):
        stat = os.stat(path)
    elif module_globals and '__loader__' in module_globals:
        name = module_globals.get('__name__')
        loader = module_globals['__loader__']
        get_source = getattr(loader, 'get_source', None)
        if name and get_source:
            try:
                data = get_source(name)
            except (ImportError, IOError):
                pass
            else:
                if data is None:
                    # No luck, the PEP302 loader cannot find the source
                    # for this module.
                    return None
                # FIXME: DRY with code below
                lines = {'plain' : data.splitlines()}
                raw_string        = ''.join(lines['plain'])
                trailing_nl       = has_trailing_nl(raw_string)
                if 'style' in opts:
                    key = opts['style']
                    highlight_opts = {'style': key}
                else:
                    key = 'terminal'
                    highlight_opts = {}

                lines[key] = highlight_array(raw_string.split('\n'),
                                    trailing_nl, **highlight_opts)
                file_cache[filename] = \
                  LineCacheInfo(None, None, lines, filename, None)
                file2file_remap[path] = filename
                return True
            pass
        pass
    if not os.path.isabs(filename):
        # Try looking through the module search path, which is only useful
        # when handling a relative filename.
        stat = None
        for dirname in sys.path:
            path = os.path.join(dirname, filename)
            if os.path.exists(path):
                stat = os.stat(path)
                break
            pass
        if not stat: return False
        pass

    try:
        mode = 'r' if PYTHON3 else 'rU'
        with open(path, mode) as fp:
                lines = {'plain' : fp.readlines()}
                eols = fp.newlines
    except:
        return None

    # FIXME: DRY with code above
    raw_string        = ''.join(lines['plain'])
    trailing_nl       = has_trailing_nl(raw_string)
    if 'style' in opts:
        key = opts['style'] or 'default'
        highlight_opts = {'style': key}
    else:
        key = 'terminal'
        highlight_opts = {}

    lines[key] = highlight_array(raw_string.split('\n'),
                                 trailing_nl, **highlight_opts)
    if orig_filename != filename:
        file2file_remap[orig_filename] = filename
        file2file_remap[os.path.abspath(orig_filename)] = filename
        pass
    pass

    file_cache[filename] = LineCacheInfo(stat, None, lines, path, None, eols)
    file2file_remap[path] = filename
    return True
1019715
def _loadcache(cachefile):
    
    cache = {}
    if os.path.exists(cachefile):
        with open(cachefile) as f:
            for line in f:
                line = line.split()
                if len(line) == 2:
                    try:
                        cache[int(line[0])] = float(line[1])
                    except:
                        pass
    return cache
353281
function Persist(cacheFile, keys, log) {
  var pdata = (cacheFile) ? JSON.parse(fs.readFileSync(cacheFile, 'utf8')) : {}
    , guid = makeGuid(keys);

  pdata[guid] = pdata[guid] || {};

  // this is the only member that needs access to the full object and the file
  this.save = function () {
    if (cacheFile) {
      fs.writeFileSync(cacheFile, JSON.stringify(pdata));
    }
  };

  // members need only know their config object
  this.cfg = pdata[guid];
  this.cfg.opts = this.cfg.opts || {};

  // was a logger passed down?
  this.log = (type.isFunction(log)) ? log : noop;
}
1119914
function FileCache(name) {
  this._filename = name || '.gulp-cache';

  // load cache
  try {
    this._cache = JSON.parse(fs.readFileSync(this._filename, 'utf8'));
  } catch (err) {
    this._cache = {};
  }
}
72186
def write_cache(cache, opts):
    '''
    
    '''
    cache_file = get_cache(opts)

    try:
        _cache = salt.utils.stringutils.to_bytes(
            salt.utils.yaml.safe_dump(cache)
        )
        with salt.utils.files.fopen(cache_file, 'wb+') as fp_:
            fp_.write(_cache)
        return True
    except (IOError, OSError):
        log.error('Failed to cache mounts',
                  exc_info_on_loglevel=logging.DEBUG)
        return False
904561
def copy_file(self, path, prefixed_path, source_storage):
        
        args = (path, prefixed_path, source_storage)
        if settings.threads:
            self.tasks.append(args)
        else:
            self.do_copy_file(args)
204005
def cache_files(self, paths, saltenv='base', cachedir=None):
        '''
        
        '''
        ret = []
        if isinstance(paths, six.string_types):
            paths = paths.split(',')
        for path in paths:
            ret.append(self.cache_file(path, saltenv, cachedir=cachedir))
        return ret
1195947
def put(self, source, rel_path, metadata=None):
        '''

        '''

        # This case should probably be deprecated.
        if not isinstance(rel_path, basestring):
            rel_path = rel_path.cache_key

        sink = self.put_stream(rel_path, metadata=metadata)

        try:
            copy_file_or_flo(source, sink)
        except (KeyboardInterrupt, SystemExit):
            path_ = self.path(rel_path)
            if os.path.exists(path_):
                os.remove(path_)
            raise

        sink.close()

        return os.path.join(self.cache_dir, rel_path)
206529
def write(file_name, file_contents, data)
      fname = cache_file_name(file_name, file_contents)
      @previous_entry = fname
      File.open(fname, "wb") {|file| Marshal::dump(data, file) }
    end
1020567
def read(filename='cache'):
	
	cache_path = get_cache_path(filename)
	if not os.path.exists(cache_path) or os.stat(cache_path).st_size == 0:
		return None
	with open(cache_path, 'r') as file:
		return json.load(file)