How to use the memory-cache.get function in memory-cache

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 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 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);
});
github yodlr / CoreGI / routes / index.js View on Github external
router.get('/api/keys', function(req, res) {
  var keys = cache.get('keys') || [];
  res.json(keys);
});
github danfang / me-api / lib / middleware / nest.js View on Github external
handler: function(req, res) {
        var cachedResult = cache.get('nest');
        if (cachedResult) return res.json(cachedResult);

        var url = NEST_API_URL + '/devices/thermostats/' +
                  this.secrets.device_id + '?auth=' +
                  this.secrets.access_token;

        var requestOpts = { url: url, headers: { 'Accept': 'application/json' } };
        request(requestOpts, function(err, response, body) {
          if (err || response.statusCode != 200) return handleError(err, res);
          var data = JSON.parse(body);
          cache.put('nest', data, DEFAULT_CACHE_MSEC);
          return res.json(data);
        });
      }
    }
github danfang / me-api / lib / middleware / mixcloud.js View on Github external
handler: function(req, res) {
        var cachedResult = cache.get('mixcloud');
        if (cachedResult) return res.json(cachedResult);

        var url = 'http://api.mixcloud.com/' + this.me + '/feed/';
        request({ url: url, headers: { 'User-Agent': this.me }}, function(err, response, body) {
          if (err || response.statusCode != 200) return handleError(err, res);
          var data = JSON.parse(body);
          cache.put('mixcloud', data, DEFAULT_CACHE_MSEC);
          return res.json(data);
        });
      }
    }
github danfang / me-api / lib / middleware / foursquare.js View on Github external
handler: function(req, res) {
        var cachedResult = cache.get('foursquare');
        if (cachedResult) return res.json(cachedResult);

        var accessToken = this.accessToken;
        if (!accessToken) return handleError('You have not specified an access Token yet', res);

        var fs = getFoursquare(req, this);
        fs.Users.getCheckins('self', {}, accessToken, function(err, checkins) {
          if (err) return handleError(err, res);

          cache.put('foursquare', checkins, DEFAULT_CACHE_MSEC);
          res.json(checkins);
        });
      }
    },
github danfang / me-api / lib / middleware / keybase.js View on Github external
handler: function(req, res) {
        var cachedResult = cache.get('keybase');
        if (cachedResult) return res.json(cachedResult);

        var url = 'https://keybase.io/_/api/1.0/user/lookup.json?usernames=' + this.me;
        request({ url: url, headers: { 'User-Agent': this.me }}, function(err, response, body) {
          if (err || response.statusCode != 200) return handleError(err, res);
          var data = JSON.parse(body);
          cache.put('keybase', data.them, DEFAULT_CACHE_MSEC);
          return res.json(data.them);
        });
      }
    },
github danfang / me-api / lib / middleware / github.js View on Github external
handler: function(req, res) {
        var cachedResult = cache.get('github');
        if (cachedResult) return res.json(cachedResult);

        var url = 'https://api.github.com/users/' + this.me + '/events/public';
        request({ url: url, headers: { 'User-Agent': this.me }}, function(err, response, body) {
          if (err || response.statusCode != 200) return handleError(err, res);
          var data = JSON.parse(body);
          cache.put('github', data, DEFAULT_CACHE_MSEC);
          return res.json(data);
        });
      }
    }
github twitterdev / account-activity-dashboard / helpers / cache-route.js View on Github external
return (request, response, next) => {
    var key = '__express__' + request.originalUrl || request.url
    var cached_response = mcache.get(key)
    if (cached_response) {
      response.send(cached_response)
      return
    } else {
      response.sendResponse = response.send
      response.send = (body) => {
        mcache.put(key, body, duration);
        response.sendResponse(body)
      }
      next()
    }
  }
}

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