Hello,
In the apigee-access docs Accessing the cache in Node.js there are the following statements:
"Inside Apigee Edge, the cache is distributed among all nodes where your Node.js application executes."
and, when discussing cache resource scope,
global
: All cache entries may be seen by all Node.js applications in the same Apigee "environment."
Does this mean that entries made to a cache resource using apigee-access from nodejs are not visible to the Edge policy LookupCache?
Is there a separation between entries made by nodejs and cache entries made by the populate cache policy?
I would like to have a proxy that uses nodejs to populate a cache resource and then have the data from the cache resource read by another non-nodejs proxy using the Lookup Cache policy.
Is that possible?
Solved! Go to Solution.
Hi @neil.munro
Yes thats possible. In the node app, you can use the apigee-access Cache object and use the put method to set a key and an object which stores it into the Cache globally. More info here. You can get the Cache object by passing the Cache name that is configured. Please use global scope, something like
var cache = apigee.getCache('CacheName', { resource: 'CacheName', scope:'global' }); cache.put("cacheKey", sresponseBody, 3600, function(err) { console.log("Cache updated") });
On the other non-node app, you can fetch using the lookup cache policy
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache-1"> <DisplayName>Lookup-Cache-1</DisplayName> <Properties/> <CacheKey> <KeyFragment>cacheKey</KeyFragment> </CacheKey> <CacheResource>CacheName</CacheResource> <Scope>Global</Scope> <AssignTo>flowVar</AssignTo> </LookupCache>
Thanks again for your response. Having the confirmation helped me find my mistake.
The problem appears to have been with the configuration of the lookup policy where we had a <Prefix> element and a <Scope> element.
From the docs (I highlighted in bold the key statement)
<Scope> or<Prefix> | Use the <Scope> or <Prefix> elements to further namespace cache keys. <Scope> enumerates a list of predefined values. The <Prefix> element overrides <Scope> with a value of your own choosing. |
So, where I had
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <LookupCache async="false" continueOnError="false" enabled="true" name="LookupCache.CustomerDashboard.Report"> <DisplayName>LookupCache.CustomerDashboard.Report</DisplayName> <Properties/> <CacheKey> <Prefix>CustomerDashboard</Prefix> <KeyFragment ref="kao.resource"/> <KeyFragment ref="kao.param.sales_group"/> <KeyFragment ref="kao.param.sales_office"/> <KeyFragment ref="kao.param.page"/> </CacheKey> <CacheResource>SFA2_CustDash</CacheResource> <Scope>Global</Scope> <AssignTo>kao.cache.report</AssignTo> </LookupCache>
It needed to be:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <LookupCache async="false" continueOnError="false" enabled="true" name="LookupCache.CustomerDashboard.Report"> <DisplayName>LookupCache.CustomerDashboard.Report</DisplayName> <Properties/> <CacheKey> <Prefix/> <KeyFragment>CustomerDashboard</KeyFragment> <KeyFragment ref="kao.resource"/> <KeyFragment ref="kao.param.sales_group"/> <KeyFragment ref="kao.param.sales_office"/> <KeyFragment ref="kao.param.page"/> </CacheKey> <CacheResource>SFA2_CustDash</CacheResource> <Scope>Global</Scope> <AssignTo>kao.cache.report</AssignTo> </LookupCache>