Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Get Cache is not working as expected #7

Closed
anil614sagar opened this issue Aug 7, 2016 · 1 comment
Closed

Get Cache is not working as expected #7

anil614sagar opened this issue Aug 7, 2016 · 1 comment

Comments

@anil614sagar
Copy link

anil614sagar commented Aug 7, 2016

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"?> <PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache-1"> <DisplayName>Populate Cache-1</DisplayName> <Properties/> <CacheKey> <KeyFragment>cachedDataKey</KeyFragment> </CacheKey> <Scope>Global</Scope> <ExpirySettings> <TimeoutInSec>3600</TimeoutInSec> </ExpirySettings> <Source>request.queryparam.cachedata</Source> </PopulateCache>

Lookup cache Policy,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache-1"> <DisplayName>Lookup Cache-1</DisplayName> <Properties/> <CacheKey> <KeyFragment>cachedDataKey</KeyFragment> </CacheKey> <Scope>Global</Scope> <AssignTo>flowVar</AssignTo> </LookupCache>

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant