Caches function result in temporary file.

    Cache will be expired when modification date of files from `depends_on`
    will be changed.

    Only functions should be wrapped in `cache`, not methods.
487963
def cache(*depends_on):
    
    def cache_decorator(fn):
        @memoize
        @wraps(fn)
        def wrapper(*args, **kwargs):
            if cache.disabled:
                return fn(*args, **kwargs)
            else:
                return _cache.get_value(fn, depends_on, args, kwargs)

        return wrapper

    return cache_decorator
427627
def delete_cached_files(self, prefixes=[], suffixes=[]):
        
        for filename in listdir(self.cache_directory_path):
            delete = (
                any([filename.endswith(ext) for ext in suffixes]) or
                any([filename.startswith(pre) for pre in prefixes]))
            if delete:
                path = join(self.cache_directory_path, filename)
                logger.info("Deleting %s", path)
                remove(path)
3800
function () {
		return utility.iterate( cache.items, function ( v, k ) {
			if ( cache.expired( k ) ) {
				cache.expire( k, true );
			}
		});
	}
1087188
def cache_control_expires(num_hours):
    
    num_seconds = int(num_hours * 60 * 60)

    def decorator(func):
        @wraps(func)
        def inner(request, *args, **kwargs):
            response = func(request, *args, **kwargs)
            patch_response_headers(response, num_seconds)
            return response

        return inner

    return decorator
785235
function cacheTemplate(fn, options) {
  if (options.cache && options.filename) {
    cache[options.filename] = fn;
  }
}
1317090
private boolean isCacheValid()
  {
    long now = CurrentTime.currentTime();

    if ((now - _lastTime < 100) && ! CurrentTime.isTest())
      return true;

    long oldLastModified = _lastModified;
    long oldLength = _length;
    
    long newLastModified = getBacking().getLastModified();
    long newLength = getBacking().length();
    
    _lastTime = now;

    if (newLastModified == oldLastModified && newLength == oldLength) {
      _lastTime = now;
      return true;
    }
    else {
      _changeSequence.incrementAndGet();
      
      // If the file has changed, close the old file
      clearCache();
      
      _zipEntryCache.clear();
      
      _lastModified = newLastModified;
      _length = newLength;
      
      _lastTime = now;

      return false;
    }
  }
824344
function _cacheFunction(func, data, vars, relPath) {
  func.engine = this.className;
  if (vars) app.views.callbacks[relPath] = func;
}
677381
def _out_of_date(func, *args, **kwargs):
    """"""
    storage_directory = os.path.join(tempfile.gettempdir(), "jobstamps")
    stamp_input = "".join([func.__name__] +
                          [repr(v) for v in args] +
                          [repr(kwargs[k])
                           for k in sorted(kwargs.keys())]).encode("utf-8")

    dependencies = kwargs.pop("jobstamps_dependencies", None) or list()
    expected_output_files = (kwargs.pop("jobstamps_output_files", None) or
                             list())
    cache_output_directory = kwargs.pop("jobstamps_cache_output_directory",
                                        None) or storage_directory
    method_class = _determine_method(kwargs.pop("jobstamps_method", None))

    stamp_file_name = os.path.join(cache_output_directory,
                                   hashlib.md5(stamp_input).hexdigest())

    detail = _OutOfDateActionDetail(stamp=stamp_file_name,
                                    dependencies=dependencies,
                                    method=method_class(stamp_file_name),
                                    kwargs=kwargs)

    if os.environ.get("JOBSTAMPS_DISABLED", None):
        return "JOBSTAMPS_DISABLED", detail

    _safe_mkdir(cache_output_directory)

    if not os.path.isdir(cache_output_directory):
        raise IOError("""{} exists and is not a directory.""".format(cache_output_directory))

    if not os.path.exists(stamp_file_name):
        return stamp_file_name, detail

    for expected_output_file in expected_output_files:
        if not os.path.exists(expected_output_file):
            return expected_output_file, detail

    for dependency in dependencies:
        if (not os.path.exists(dependency) or
                not detail.method.check_dependency(dependency)):
            return dependency, detail

    return None, detail
1212981
function hasOutDatedTemplateCache (mainCompilation) {
  const childCompiler = getChildCompiler(mainCompilation.compiler);
  /**
   * @type {WeakMap<HtmlWebpackChildCompiler, boolean>|undefined}
   */
  let hasOutdatedChildCompilerDependenciesMap = hasOutdatedCompilationDependenciesMap.get(mainCompilation);
  // Create map for childCompiler if none exist
  if (!hasOutdatedChildCompilerDependenciesMap) {
    hasOutdatedChildCompilerDependenciesMap = new WeakMap();
    hasOutdatedCompilationDependenciesMap.set(mainCompilation, hasOutdatedChildCompilerDependenciesMap);
  }
  // Try to get the `checkChildCompilerCache` result from cache
  let isOutdated = hasOutdatedChildCompilerDependenciesMap.get(childCompiler);
  if (isOutdated !== undefined) {
    return isOutdated;
  }
  // If `checkChildCompilerCache` has never been called for the given
  // `mainCompilation` and `childCompiler` combination call it:
  isOutdated = isChildCompilerCacheOutdated(mainCompilation, childCompiler);
  hasOutdatedChildCompilerDependenciesMap.set(childCompiler, isOutdated);
  return isOutdated;
}
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);
      });

    });
  }
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;
}
55447
def method_for_cached(object, key, fetch_method=:fetch, method_name=nil)
      method_name = ("cached_" + (method_name || key)).gsub(/[^\w\!\?]/, '_')
      method_body = <<-END
        def #{method_name}(*args, &block)
          opts = args.empty? ? {} : args.first

          proxy = AridCache::CacheProxy.new(self, #{key.inspect}, opts, &block)
          if opts[:clear] == true
            proxy.clear_cached
          else
            proxy.#{fetch_method.to_s}
          end
        end
      END
      # Get the correct object
      object = (class << object; self; end) if object.is_a?(Class)
      object.class_eval(method_body, __FILE__, __LINE__)
    end
367238
def cached(func, instance, args, kwargs):
    """"""
    cache = getattr(instance, "__cache", None)
    if cache is None:
        instance.__cache = cache = {}
    try:
        return cache[func]
    except KeyError:
        cache[func] = result = func(*args, **kwargs)
        return result
116709
function cached (fn) {
  var cache = Object.create(null);
  return (function cachedFn (str) {
    var hit = cache[str];
    return hit || (cache[str] = fn(str))
  })
}
227556
function MustUseCache()
    {
        if ($this->cacheLifetime == 0)
        {
            return false;
        }
        if (!File::Exists($this->file))
        {
            return false;
        }
        $now = Date::Now();
        $lastMod = File::GetLastModified($this->file);
        if ($now->TimeStamp() - $lastMod->TimeStamp() < $this->cacheLifetime)
        {
            return true;
        }
        return false;
    }
141396
def browser_cache(seconds):
    
    import web
    def wrap(f):
        def wrapped_f(*args):
            last_time_str = web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '')
            last_time = web.net.parsehttpdate(last_time_str)
            now = datetime.datetime.now()
            if last_time and\
                    last_time + datetime.timedelta(seconds = seconds) > now:
                web.notmodified()
            else:
                web.lastmodified(now)
                web.header('Cache-Control', 'max-age='+str(seconds))
            yield f(*args)
        return wrapped_f
    return wrap
755634
def disk_cache(cls, basename, function, *args, method=True, **kwargs):
        
        @utility.disk_cache(basename, cls.directory(), method=method)
        def wrapper(*args, **kwargs):
            return function(*args, **kwargs)

        return wrapper(*args, **kwargs)