Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

NodeJS Cache - Retrieve data and push to array

Not applicable

Hi,

My requirement is to retrieve data from cache and populate an array in NodeJS...I have used apigee-access module to create and populate the cache.

But for some reason my array is empty when printed outside the callback

Code Snippet

var cacheResp = [];
cache.get(cacheKey,function(err, data) {
  cacheResp.push(data);
  console.log("**** Cache 1: **** " + cacheResp);
}); 
console.log("**** Cache 2: **** " + cacheResp);

In the output I see log Cache 1 with contents of CacheResp array but Cache2 is empty..
Can you please help
0 3 5,084
3 REPLIES 3