Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to cache a response I get from a Javascript policy?

Hi,

I've a javascript policy, inside the javascript policy im doing som rest callouts to other apis for fetcing some values. Now this callout takes 500ms and is somewhat static. So caching it would really fit in here to make everything super fast.

This is how my javascript callout look like:

keykey = context.getVariable("somecachedkey");
if(keykey)
{
    throw "caching is working!";   
}
var myRequest = new Request('http://someadress.com/api',"GET");
var test = httpClient.send(myRequest);
test.waitForComplete();
if (!test.isSuccess()) {
    throw 'Error contacting geocoding web service';
}
context.setVariable("somecachedkey", test.getResponse().content.asJSON.value);

It works fine.

I've read some about caching and I thought the populate cache policy was the one I was aiming for.

And I created a polulate cache policy but when trying to deploy it I get the error:

Invalid cache resource reference in Step definition <CachePolicyName>

I read that this should solve it: https://docs.apigee.com/api-platform/cache/manage-caches-environment

Which is great because I want the cached used by other api proxies. But I don't really understand how to configure everything. From checking the cache in my javascript policy, using a cache policy thats fetches a variable from the javascript step and sharing the cache between multiple proxies.

Solved Solved
0 10 1,189
1 ACCEPTED SOLUTION

You'll need to create a cache using the Admin menu, in the same environment where you've deployed your proxy and with the same name you're using in the CachePolicyName attribute

View solution in original post

10 REPLIES 10
Top Solution Authors