apigee / apigee-access

The "apigee-extensions" module for Node.js, which lets Node.js apps access Apigee-specific information
MIT License
6 stars 3 forks source link

Get Cache is not working as expected #7

Closed anil614sagar closed 8 years ago

anil614sagar commented 8 years ago

Unable to retrieve cache value populated using Popualate Cache Policy. It works using Lookup cache policy, but it doesn't work using Apigee Access,

`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Populate Cache-1 cachedDataKey Global 3600 request.queryparam.cachedata ` Lookup cache Policy, ` Lookup Cache-1 cachedDataKey Global flowVar ` Apigee Access ``` var key = 'ORGNAME__ENVNAME____cachedDataKey'; var customCache = apigee.getCache('MyCustomCache', { scope: 'global'} ); console.log("hello"); customCache.get(key, function (err, data) { console.log("value is " + data); resp.writeHead(200, {"Content-Type": "application/json"}); resp.end(JSON.stringify({ err: err, data: { key: key, value: data ? data : 'undefined' } })); }); ```
anil614sagar commented 8 years ago
var http = require('http');
var apigee = require('apigee-access');

console.log('node.js application starting...');

var svr = http.createServer(function(req, resp) {

  var key = 'cachedDataKey'; // just key name
  // cacheResourceName
  var customCache = apigee.getCache('apigeeAccessCache',
  { scope: 'global'} );

  console.log("hello");

  customCache.get(key, function (err, data) {
    console.log("value is " + data);
    resp.writeHead(200, {"Content-Type": "application/json"});
    resp.end(JSON.stringify({
      err: err,
      data: {
        key: key,
        value: data ? data : 'undefined'
      }
    }));
  });
});

svr.listen(9000, function() {
    console.log('Node HTTP server is listening');
});

It works as expected, i messed up keys & cache name