How to use memory-cache - 10 common examples

To help you get started, we’ve selected a few memory-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ovh-ux / ovh-chatbot / config / middlewares / verifyOvhUser.js View on Github external
request(options, (err, resp, body) => {
        if (err || resp.statusCode >= 400) {
          return reject(resp && resp.statusCode ? { statusCode: resp.statusCode, data: body } : { statusCode: 500, data: err });
        }
        cache.put(req.cookies.SESSION, JSON.stringify(body), config.web.cacheTime); // Cache the response for the next 2000 ms
        return resolve(body);
      });
    })
github Mailtrain-org / mailtrain / routes / subscription.js View on Github external
res.render('subscription/widget-subscribe', data, (err, html) => {
                        if (err) {
                            return sendError(err);
                        }

                        let response = {
                            data: {
                                title: data.title,
                                cid: data.cid,
                                html
                            }
                        };

                        cache.put(req.path, response, 30000); // ms
                        res.status(200).json(response);
                    });
                });
github alexose / sieve / lib / helpers.js View on Github external
toCache : function(entry, data, all){

    // TODO: Respect cache headers from response
    var time = (entry.cache || 60 * 60 * 24) * 1000
      , max = 2147483647  // http://stackoverflow.com/questions/3468607
      , key = this.hash(entry, all);

    time = time > max ? max : time;

    cache.put(key, data, time);

    return true;
  },
  hash : function(){
github trulia / webpagetest-charts-api / routes / tests.js View on Github external
function getCache(req) {
  const key = cacheKey(req);
  const data = cache.get(key);

  debug("getting cache key: " + key);
  debug(data);

  return data;
}
github trulia / webpagetest-charts-api / routes / tests.js View on Github external
function setCache(req, data) {
  const key = cacheKey(req);

  debug("setting cache key: " + key);
  debug(data);

  return cache.put(key, data, 1000 * (60 * 60));
}
github DataFire / DataFire / src / lib / project-server.js View on Github external
res.end = (body, encoding) => {
              let toCache = {body, headers:res.header()._headers};
              memCache.put(req.cacheKey, toCache, cacheTime)
              return origEnd(body, encoding);
            }
            next();
github pterodactyl / daemon / src / helpers / config.js View on Github external
constructor() {
        if (_.isNull(Cache.get('config'))) {
            Cache.put('config', this.raw());
        }
    }
github yodlr / CoreGI / lib / fleetctl.js View on Github external
fleet.fc.list_machines(function(err, machines){
    if(err) {
      log.error({err: err}, 'Error - Fleetctl: listMachines');
      cache.del('machines');
    }
    else if(machines) {
      log.debug({data: machines}, 'Fleetctl: listMachines');
      cache.put('machines', machines);
    }
    callback(null);
  });
};
github guanzo / vote-to-play / server / src / routes / data-route.js View on Github external
async function getWargamingData({ url, fields, cacheKey, parseDataCb }) {
	let data = cache.get(cacheKey)
	if(data === null){
		data = await requestWargamingData(url, fields, parseDataCb);
		cache.put(cacheKey, data, CACHE_EXPIRE)
	}
	return data;
}
github yodlr / CoreGI / routes / index.js View on Github external
router.get('/api/machines', function(req, res) {
  var machines = cache.get('machines') || [];
  res.json(machines);
});

memory-cache

A simple in-memory cache. put(), get() and del()

BSD-2-Clause
Latest version published 7 years ago

Package Health Score

68 / 100
Full package analysis

Popular memory-cache functions