Apigee Caching - How to check if the flowvariable is null or has data?

Not applicable

Iam trying to host a WCF REST service in apigee. I want to cache few master datas-mediocre JSON objects. All i understand from Apigee docs is , i can define Flows and configure policies in my proxy to lookup a cached item and then decide whether to make REST call or not. I specify the variable in my LookUpPolicy. How do i check whether this variable has data or not and then proceed with the REST call? Sorry if its a simple question, i am confused and dont find a simple way to get this done

0 3 1,014
3 REPLIES 3

Not applicable

Hello @Swarna,

You can use the Javascript policy. And in the javascript logic you can do a check like this

var myLookUpData = "";

myLookUpData = context.getVariable("myCachedData"); //Assuming the lookup cache policy storing the fetched data in myCachedData

if (!myLookUpData) {

	//Implies data is null
} else {

	//Implies data is not null
}

You can check for the lookupcache.{policy-name}.cachehit (=false|true) variable to detect if the object was found in cache or not. Use that variable inside of <Step><Condition> to conditionally execute that step(s) if the variable evaluates to true. Alternatively, you can also use the variable set in the <AssignTo> element of the lookupcache policy and evaluate that for null in the step condition.

Not applicable

Hi,

You can check variable === undefined or variable === null. Using this condition you can identify variable is null or not