Lazy-load and cache extensions and languages
333045
function map() {
  var cache = {};
  if (!cache.extensions) cache.extensions = require('./lib/exts.json');
  if (!cache.languages) cache.languages = require('./lib/lang.json');
  return cache;
}
900319
function lazy(schema, defaults, options) {
  if (kindOf(schema) !== 'function') {
    if (process.env.NODE_ENV !== 'production') {
      throw new Error(
        `Lazy structs must be defined as an function that returns a schema, but you passed: ${schema}`
      )
    } else {
      throw new Error(`Invalid schema: ${schema}`)
    }
  }

  let kind
  let struct
  const name = 'lazy'
  const type = `lazy...`
  const compile = value => {
    struct = schema()
    kind.name = struct.kind
    kind.type = struct.type
    kind.validate = struct.validate
    return kind.validate(value)
  }

  kind = new Kind(name, type, compile)
  return kind
}
410955
def supported_cache_type(types):
    
    if isinstance(types, str):
        types = [typ.strip() for typ in types.split(",")]
    for typ in types:
        if typ not in ["reflink", "hardlink", "symlink", "copy"]:
            return False
    return True
460723
private void lazyInit() {

    if (tokenToPosTagMap != null) {
      return;
    }

    Map<String, List<MultiWordEntry>> map = new HashMap<>();

    try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(filename)) {
      List<String> posTokens = loadWords(stream);

      for (String posToken : posTokens) {
        String[] tokenAndTag = posToken.split("\t");
        if (tokenAndTag.length != 2) {
          throw new RuntimeException("Invalid format in " + filename + ": '" + posToken + "', expected two tab-separated parts");
        }
        
        String[] tokens = tokenAndTag[0].split(" ");
        String posTag = tokenAndTag[1];
        
        List<MultiWordEntry> multiwordItems;
        if( map.containsKey(tokens[0]) ) {
          multiwordItems = map.get(tokens[0]);
        }
        else {
          multiwordItems = new ArrayList<>();
          map.put(tokens[0], multiwordItems);
        }
        
        multiwordItems.add(new MultiWordEntry(Arrays.asList(tokens), posTag));
      }
      
      tokenToPosTagMap = map;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
488372
def memoize(func):
    """"""
    cache = {}

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        """Caching wrapper."""
        key = (args, tuple(sorted(kwargs.items())))
        if key in cache:
            return cache[key]
        else:
            result = func(*args, **kwargs)
            cache[key] = result
            return result

    return wrapper
782822
function Loader(regex) {
    this.cache = Object.create(null);
    this.map = Object.create(null);
    this.requests = 0;
    this.regex = regex;
  }
358465
def update_cache(func):
    
    @wraps(func)
    def wrapper(self, *args, **kwargs):
        """The wrapper function."""
        lazy = kwargs.get('lazy', False)
        kwargs.pop('lazy', None)

        if not lazy:
            self.get_json()

        ret = func(self, *args, **kwargs)

        # If returning a string assume it is an update message
        if isinstance(ret, str) and not lazy:
            self.set_json(ret)
        else:
            return ret

    return wrapper
1302387
function cacher(f, scope, postprocessor) {
            function repush(array, item) {
                for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
                    return array.push(array.splice(i, 1)[0]);
                }
            }
            function newf() {
                var arg = Array.prototype.slice.call(arguments, 0), args = arg.join("␀"), cache = newf.cache = newf.cache || {}, count = newf.count = newf.count || [];
                if (cache.hasOwnProperty(args)) {
                    repush(count, args);
                    return postprocessor ? postprocessor(cache[args]) : cache[args];
                }
                if (count.length >= 1e3) {
                    delete cache[count.shift()];
                }
                count.push(args);
                cache[args] = f.apply(scope, arg);
                return postprocessor ? postprocessor(cache[args]) : cache[args];
            }
            return newf;
        }
193726
def cache(self):
        """"""
        cache = self._cache or self.app.config.get('COLLECTIONS_CACHE')
        return import_string(cache) if isinstance(cache, six.string_types) \
            else cache
416111
def load(path, cache=None, precache=False):
    
    parser = Stylesheet(cache)
    return parser.load(path, precache=precache)
468900
protected final void loadExtensionCache() {
                // threshold for discarding old cache files
                long minModified = System.currentTimeMillis() - MAX_CACHE_MILLIS;
                File extFolder = XRuntimeUtils.getExtensionCacheFolder();
                XExtension extension;
                File[] extFiles = extFolder.listFiles();
                if (extFiles == null) {
                        // Extension folder may be non-existant for virtual users with no
                        // home directory
                        XLogging.log(
                                "Extension caching disabled (Could not access cache directory)!",
                                XLogging.Importance.WARNING);
                        return;
                }
                for (File extFile : extFiles) {
                        if (extFile.getName().toLowerCase().endsWith(".xesext") == false) {
                                // no real extension
                                continue;
                        }
                        if (extFile.lastModified() < minModified) {
                                // remove outdated cache files
                                if (extFile.delete() == false) {
                                        extFile.deleteOnExit();
                                }
                        } else {
                                // load extension file
                                try {
                                        extension = XExtensionParser.instance().parse(extFile);
                                        if (extensionMap.containsKey((extension).getUri()) == false) {
                                                extensionMap.put(extension.getUri(), extension);
                                                extensionList.add(extension);
                                                XLogging.log(
                                                        "Loaded XES extension '" + extension.getUri()
                                                        + "' from cache",
                                                        XLogging.Importance.DEBUG);
                                        } else {
                                                XLogging.log("Skipping cached XES extension '"
                                                        + extension.getUri() + "' (already defined)",
                                                        XLogging.Importance.DEBUG);
                                        }
                                } catch (IOException | ParserConfigurationException | SAXException e) {
                                        // ignore bad apples for now
                                        e.printStackTrace();
                                }
                        }
                }

        }
785235
function cacheTemplate(fn, options) {
  if (options.cache && options.filename) {
    cache[options.filename] = fn;
  }
}
227774
def _cached_search_compile(pattern, re_verbose, re_version, pattern_type):
    """"""

    return _bregex_parse._SearchParser(pattern, re_verbose, re_version).parse()
595089
function (str, options, cb) {
    var tmpl = this.cache(options) || this.cache(options, this.engine.compile(str, options));
    tmpl.eval(options, function(str){
      cb(null, str);
    });
  }
658387
def enable_cache():
    """"""
    try:
        import requests_cache
    except ImportError as err:
        sys.stderr.write('Failed to enable cache: {0}\n'.format(str(err)))
        return
    if not os.path.exists(CACHE_DIR):
        os.makedirs(CACHE_DIR)
    requests_cache.install_cache(CACHE_FILE)
1086616
def inheritable_cache_get(formats, name, partial, param)
      prefixes = formats.collect { |format| inheritable_cache[format.to_sym][partial][name][param] }
      prefixes.compact!
      prefixes.empty? ?  nil : prefixes.first
    end
135081
def lazy_result(f):
    """"""
    @wraps(f)
    def decorated(ctx, param, value):
        return LocalProxy(lambda: f(ctx, param, value))
    return decorated