How to remove a cache using Node.Js

Hi,

I have implemented a custom caching where we are looking up and populating the cache.

Below is the code.

<LookupCache name="Cache.lookupCacheKey"> 
  <DisplayName>Cache.lookupCacheKey</DisplayName> 
  <CacheKey> 
    <Prefix/> 
    <KeyFragment ref="cacheKey"/> 
  </CacheKey> 
  <CacheResource>abc</CacheResource> 
  <Scope>Global</Scope> 
  <AssignTo>cachingInfo</AssignTo> 
</LookupCache>

When I am trying to remove this using node js it is still fetching me the response from cache.

var http = require('http');
var apigee = require('apigee-access');
var cache = apigee.getCache('cache', { resource: 'abc', scope: 'global'} );
cache.remove('cacheKey', function(error) { });
console.log('node.js application starting...');
var svr = http.createServer(function(req, resp) { resp.end('Hello, World!'); });
svr.listen(9000, function() { console.log('Node HTTP server is listening'); });

Am I missing anything?

Thanks in Advance.

0 2 5,540
2 REPLIES 2

Yes, I think you are missing something.

What do you mean by "still"? Can you describe the order of your actions?

Deploy proxy, invoke API, populate cache, lookup cache..... in which order are you performing these steps? And what do you expect to see?

The reason I ask ... The nodejs code includes a call to cache.remove() that appears in the startup code of the nodejs app. That happens once, when the API Proxy is deployed. It won't happen again, until you re-deploy the API Proxy.

You'll have to think about how and when you would like to clear the cache. The way you have the code now, it doesn't seem like it will be very useful to you.

@Dino: I have created a node js proxy. I have deployed my proxy and when API is invoked, firstly i will lookup the cache in the cache resource. If the cacheResource does not have it, then populateCache will be invoked. After that what i am trying to do is creating a nodejs in which i can remove the cacheKey from the cacheResource so that the next time the API is invoked it again populates the required key in the cache.

Note: This is just a small POC i am trying to build.