Unable to read LookUpCache cache-hit variable inside JavaScript.

When I am trying to read the cache-hit variable inside JavaScript policy. JS policy execution got failed and I see the following error on Message processor System.log.

RhinoExecutor$TopLevelScope.print() : ReferenceError: "lookupcache" is not defined.

JavaScript policy JS File code:

if(lookupcache.{policy-name}.cachehit !==true){    

 ///code

}

FYI information - LookUpCache policy is executing before JS policy.

0 2 159
2 REPLIES 2

The JavaScript API does not expose "lookupcache", please review the JavaScript reference for more details: https://docs.apigee.com/api-platform/reference/javascript-object-model

Yes. And I think the OP needs something more like this :

var cachehit = context.getVariable('lookupcache.POLICYNAME.cachehit');
...

The key observation here:

variables in the Apigee request context (aka context variables) are contained in a scope that is different than variables inside the JavaScript execution context.

To access a context variable in a JS, you need to use "context.getVariable()" from within your JS.