caching through node js,caching through node js in apigee using memory-cache

Not applicable

caching through node js is not persisting data . My requirement is to add email ids as keys and string arrays as value again that keys. the bold line gives me null most of the time and it overwrites if i give new string. below are my codes.

var http = require('http');
var apigee = require('apigee-access');
var mcache = require('memory-cache');
http.createServer(function (request, response) {
  var devemail = apigee.getVariable(request, 'developer.email');
  var dataset = "welcome2018";
  var Data = [];
  var old = mcache.get(devemail);
  var mkeys = _mcache.keys();
  var oldval = _mcache.exportJson();
  res = "mkeys:" + mkeys;
  if (null !== devemail && null !== dataset) {
    Data.push(dataset);
    mcache.put(devemail, Data);
  }
  res = res + "\nuser email :" + devemail + ",\n" + "cachedatasets :" + mcache.get(devemail);
  response.end(res) console.log(response);
}).listen(9001);, want to store email id as key and string array as value.On access of the same email id, value needs to be added in the string array.used 'memory-cache', and tried to put email id as key and string value in array, but it doesnt store the value in cache
for few seconds.Cache hits is always 0 my codes are like this: var http = require('http');
var apigee = require('apigee-access');
var mcache = require('memory-cache');
http.createServer(function (request, response) {
  var devemail = apigee.getVariable(request, 'developer.email');
  var Data = [];
  var dataset = "welcome2018";
  var Data = [];
  var mkeys = _mcache.keys();
  var oldval = _mcache.exportJson();
  res = "mkeys:" + mkeys;
  if (null !== devemail && null !== dataset) {
    Data.push(dataset);
    mcache.put(devemail, Data);
  }
  res = res + "\nuser email :" + devemail + ",\n" + "cachedatasets :" + mcache.get(devemail);
  response.end(res) console.log(response);
}).listen(9001);

0 1 193
1 REPLY 1

Not applicable

Could you please elaborate more on "caching through node js is not persisting data"?

Please be more specific with code explaining what your input is and what you expect as an output using apigee.getCache. Alternatively, if you want to avoid callback hell, you can try using apigee-cache-promise, a wrapper that primisifies of apigee-access cache callback functions.