Cache middleware configuration
350684
function configure(cacheType, conf) {
    // Check for custom logging functions on cache (debug)
    if (conf && conf.logger) {
        logger_1.configureLogger(conf.logger);
        logger_1.logger.info('Custom cache logger configured');
    }
    if (cacheType)
        exports.cache = cacheType;
}
973751
def cache(cache_directory_path):
    """"""
    if not cache_directory_path:
        click.secho(dtool_config.utils.get_cache(
            CONFIG_PATH,
        ))
    else:
        click.secho(dtool_config.utils.set_cache(
            CONFIG_PATH,
            cache_directory_path
        ))
1008663
def _use_cache(self, key, options=None):
    
    flag = ContextOptions.use_cache(options)
    if flag is None:
      flag = self._cache_policy(key)
    if flag is None:
      flag = ContextOptions.use_cache(self._conn.config)
    if flag is None:
      flag = True
    return flag
1176358
def set_cache_buster(self, path, hash):
        """"""
        oz.aws_cdn.set_cache_buster(self.redis(), path, hash)
1178245
function () {
        Shared.initialize('/config', process.argv[2]);
        Shared.setAppHttp(appHttp);
        Shared.setAppHttps(appHttps);
        Shared.setExpress(express);

        // Init memcached
        var memcached = Shared.memcached();

        // Init redis cache
        var redis = Shared.redis(true);

        //Enable gzip compression
        appHttp.use(compression());
        appHttp.disable('x-powered-by');
        appHttps.use(compression());
        appHttps.disable('x-powered-by');

        var env = Shared.config("environment");
        var maxLag = env.maxLag;
        if (maxLag) {
            toobusy.maxLag(maxLag);
        }

        appHttp.use(function (req, res, next) {
            if (maxLag && toobusy()) {
                Logger.error("Server is busy, rejected request");
                res.status(503).send("I'm busy right now, sorry.");
            } else {
                next();
            }
        });

        appHttps.use(function (req, res, next) {
            if (maxLag && toobusy()) {
                Logger.error("Server is busy, rejected request");
                res.status(503).send("I'm busy right now, sorry.");
            } else {
                next();
            }
        });

        return Q();
    }
170349
@Override
    public void configureWriteCache(long initDelay, long delayCache, long cacheSize){
        client.initTimer(initDelay, delayCache,cacheSize);
    }
640588
function(type,options){
  var cacheKey = type + ':' + options.host + ':' + options.port
  if(!cache[cacheKey]){
    debug('cache miss',cacheKey)
    var reqDefaults = {
      rejectUnauthorized: false,
      json: true,
      timeout:
        +process.env.REQUEST_TIMEOUT ||
        +options.timeout ||
        2147483647, //equiv to timeout max in node.js/lib/timers.js
      pool: pool
    }
    if(options.username || (config[type] && config[type].username)){
      reqDefaults.auth = {
        username: options.username || config[type].username
      }
    }
    if(options.password || (config[type] && config[type].password)){
      if(reqDefaults.auth){
        reqDefaults.auth.password = options.password || config[type].password
      } else {
        reqDefaults.auth = {
          password: options.password || config[type].password
        }
      }
    }
    var req = request.defaults(reqDefaults)
    cache[cacheKey] = extendRequest(req,type,options)
  } else {
    debug('cache hit',cacheKey)
  }
  return cache[cacheKey]
}
753637
public function cache() {
        $config = array();

        foreach (Cache::configured() as $key) {
            $temp = Cache::config($key);
            $config[$key] = $temp['settings'];
        }

        ksort($config);

        $this->set('configuration', $config);
    }
823696
function cache(options, compiled) {
  // cachable
  if (compiled && options.filename && options.cache) {
    delete templates[options.filename];
    cacheStore[options.filename] = compiled;
    return compiled;
  }
  // check cache
  if (options.filename && options.cache) {
    return cacheStore[options.filename];
  }
  return compiled;
}
117937
def template_cache_configured?
      if defined?(Rails)
        defined?(ActionController::Base) && ActionController::Base.perform_caching
      else
        Rabl.configuration.perform_caching
      end
    end
968211
function middlewareFunction (req,res,next){

  return ipToLocation(req.ip)
    .then(function (location) {
      req.location = location;
      next();
    })
    .catch(function (error) {
      req.locationError = error;
      next();
    })

}
1252055
function configureMiddlewares(app, config) {
    config = config || {};

    // setup request helpers
    utils.extendHttpRequest();

    // setup response helpers
    utils.extendHttpResponse();

    //
    // order is meaningful for some express middlewares
    //

    // NOTE: this should be the first middleware
    if (config.logger) {
        app.use(require('./logger')(config.logger));
    }

    // NOTE: this should be placed "high" within middleware stack
    if (config.compress || config.compression) {
        app.use(require('compression')(config.compress || config.compression));
    }

    // NOTE: this should be before "session" middleware using "cookie store"
    if (config.cookieParser) {
        app.use(require('cookie-parser')(config.cookieParser));
    }

    // "_method" body param or "x-http-method-override' header
    if (config.methodOverride) {
        app.use(require('method-override')(config.methodOverride));
    }

    // "cors" request
    if (config.cors) {
        app.use(require('./cors')(config.cors));
    }

    // NOTE: this should be before "passport" middlewares
    if (config.session) {
        app.use(require('./session')(config.session));
    }

    // this should be after "session" middleware
    if (config.csrf || config.csurf) {
        app.use(require('csurf')(config.csrf || config.csurf));
    }

    // multipart/form-data
    if (config.multipart) {
        app.use(require('./multipart')(config.multipart));
    }

    // application/json
    if (config.json) {
        app.use(require('body-parser').json(config.json));
    }

    // application/x-www-form-urlencoded
    if (config.urlencoded) {
        config.urlencoded.extended = !!config.urlencoded.extended;
        app.use(require('body-parser').urlencoded(config.urlencoded));
    }

    // plain/text
    if (config.text) {
        app.use(require('body-parser').text(config.text));
    }

    // application/octet-stream
    if (config.raw) {
        app.use(require('body-parser').raw(config.text));
    }

    return app;
}
433698
function middleware(filename, options, cb) {
  var self = this;
  var cache = self.cache;
  var handlebars = self.handlebars;

  self.async = async();

  // grab extension from filename
  // if we need a layout, we will look for one matching out extension
  var extension = path.extname(filename);

  // If passing the locals as data, create the handlebars options object now
  var handlebarsOpts = (self.__localsAsData) ? { data: options._locals } : undefined;

  // render the original file
  // cb(err, str)
  function render_file(locals, cb) {
    // cached?
    var template = cache[filename];
    if (template) {
      return cb(null, template(locals, handlebarsOpts));
    }

    fs.readFile(filename, 'utf8', function(err, str){
      if (err) {
        return cb(err);
      }

      var template = handlebars.compile(str);
      if (locals.cache) {
        cache[filename] = template;
      }

      try {
        var res = template(locals, handlebarsOpts);
        self.async.done(function(values) {
          Object.keys(values).forEach(function(id) {
            res = res.replace(id, values[id]);
          });

          cb(null, res);
        });
      } catch (err) {
        err.message = filename + ': ' + err.message;
        cb(err);
      }
    });
  }

  // render with a layout
  function render_with_layout(template, locals, cb) {
    render_file(locals, function(err, str) {
      if (err) {
        return cb(err);
      }

      locals.body = str;

      var res = template(locals, handlebarsOpts);
      self.async.done(function(values) {
        Object.keys(values).forEach(function(id) {
          res = res.replace(id, values[id]);
        });

        cb(null, res);
      });
    });
  }

  var layout = options.layout;

  // user did not specify a layout in the locals
  // check global layout state
  if (layout === undefined && options.settings && options.settings['view options']) {
    layout = options.settings['view options'].layout;
  }

  // user explicitly request no layout
  // either by specifying false for layout: false in locals
  // or by settings the false view options
  if (layout !== undefined && !layout) {
    return render_file(options, cb);
  }

  var view_dirs = options.settings.views;

  var layout_filename = [].concat(view_dirs).map(function (view_dir) {
    var view_path = path.join(view_dir, layout || 'layout');

    if (!path.extname(view_path)) {
      view_path += extension;
    }

    return view_path;
  });

  var layout_template = layout_filename.reduce(function (cached, filename) {
    if (cached) {
      return cached;
    }

    var cached_file = cache[filename];

    if (cached_file) {
      return cache[filename];
    }

    return undefined;
  }, undefined);

  if (layout_template) {
    return render_with_layout(layout_template, options, cb);
  }

  // TODO check if layout path has .hbs extension

  function cacheAndCompile(filename, str) {
    var layout_template = handlebars.compile(str);
    if (options.cache) {
      cache[filename] = layout_template;
    }

    render_with_layout(layout_template, options, cb);
  }

  function tryReadFileAndCache(templates) {
    var template = templates.shift();

    fs.readFile(template, 'utf8', function(err, str) {
      if (err) {
        if (layout && templates.length === 0) {
          // Only return error if user explicitly asked for layout.
          return cb(err);
        }

        if (templates.length > 0) {
          return tryReadFileAndCache(templates);
        }

        return render_file(options, cb);
      }

      cacheAndCompile(template, str);
    });
  }

  tryReadFileAndCache(layout_filename);
}
906328
def cache(opts, serial):
    '''
    
    '''
    return LazyLoader(
        _module_dirs(opts, 'cache', 'cache'),
        opts,
        tag='cache',
        pack={'__opts__': opts, '__context__': {'serial': serial}},
    )
491378
protected function loadMiddleware()
    {
        $middlewareLoader = new MiddlewareLoader($this->getClassLoader());
        $middlewareLoader->initialize();

        $this->setConfig("runtime.middlewares", $middlewareLoader->getMiddlewares());
    }
573636
function compose(middlewares, options = {}) {
  const { beforeRunMiddleware } = options;// before invoking the middleware, check whether can be run

  // all middleware should be function
  if (!Array.isArray(middlewares)) middlewares = [middlewares];
  for (const mw of middlewares) {
    if (typeof mw !== 'function') throw new TypeError('middleware should be a function');
  }

  return function ComposedMiddleware(req, resp, next) {
    let doRunMiddleware;

    let lastIndex = -1;// last run middleware index
    const runMiddleware = (index) => {
      if (lastIndex >= index) {
        return Promise.reject(new Error('next() called multiple times'));
      }
      lastIndex = index;

      const middleware = middlewares[index];
      if (middleware && beforeRunMiddleware) {
        return Promise.resolve(beforeRunMiddleware(middleware, req, resp)).then((canRun) => {
          if (!canRun) return runMiddleware(index + 1);
          else return doRunMiddleware(index);
        });
      }

      return doRunMiddleware(index);
    };

    doRunMiddleware = (index) => {
      let middleware = middlewares[index];
      const nextIndex = index + 1;

      let runNextMiddleware = noop;
      if (!middleware) {
        if (next) middleware = next;
      } else if (middlewares[nextIndex] || next) {
        runNextMiddleware = () => runMiddleware(nextIndex);
      }

      try {
        let result;
        if (middleware) result = middleware.call(this, req, resp, runNextMiddleware);
        return Promise.resolve(result);
      } catch (e) {
        return Promise.reject(e);
      }
    };

    return runMiddleware(0);
  };
}
122172
def cache_node(node, provider, opts):
    '''
    
    '''
    if isinstance(opts, dict):
        __opts__.update(opts)

    if 'update_cachedir' not in __opts__ or not __opts__['update_cachedir']:
        return

    if not os.path.exists(os.path.join(__opts__['cachedir'], 'active')):
        init_cachedir()

    base = os.path.join(__opts__['cachedir'], 'active')
    provider, driver = provider.split(':')
    prov_dir = os.path.join(base, driver, provider)
    if not os.path.exists(prov_dir):
        os.makedirs(prov_dir)
    path = os.path.join(prov_dir, '{0}.p'.format(node['name']))
    mode = 'wb' if six.PY3 else 'w'
    with salt.utils.files.fopen(path, mode) as fh_:
        salt.utils.msgpack.dump(node, fh_, encoding=MSGPACK_ENCODING)