Sample: Using Node.js caching with Edge policies

2 1 708

We often get questions about the caching feature in the Node.js "apigee-access" module and how it interacts with the "LookupCache" and "PopulateCache" policies.

This is a sample that shows how the two sets of functionality can work together. It consists of two API proxy bundles:

edgeproxy.zip: An Apigee Edge proxy that uses the LookupCache and PopulateCache policies to cache items in the Edge cache.

nodeproxy.zip: A Node.js application that uses "apigee-access" to access and modify the same entires in the same cache.

To use, deploy both proxies to your Apigee Edge organization.

(Both of these proxies depend on a "cache resource" called "mycache." They will not deploy unless you create that first. Alternately, you can experiment by removing the cache resource name and all the code will use the default cache resource.)

Once they are deployed:

To put something in the cache:

curl http://XXX.apigee.net/edgecache?key=baz -X PUT -H "Content-Type: text/plain" -d 'SOME DATA"
OR:
curl http://XXX.apigee.net/nodecache?key=baz -X PUT -H "Content-Type: text/plain" -d 'SOME DATA"
You will see using the URLs above that both the Edge proxies and the Node.js code are using the same cache and both can insert and retrieve the same entries.
Feel free to experiment with the code, or post here if you have more questions!
Comments
sunin_shah
New Member
@Greg Brail

Thanks for the sample. Have you tried the same after adding a Prefix? I cannot get my setup working when I use prefix.

Version history
Last update:
‎03-21-2016 04:01 PM
Updated by: