LookupCache never results in cache hit when cache populated with nodejs

Not applicable

Hi

We are trying to populate a cache from node and then retrieve it from a Lookup Cache policy but always get cache hit: false

Our lookup:

<LookupCache name="Lookup-Cache-1">
  <DisplayName>Lookup Cache-1</DisplayName>
  <Properties/>
  <CacheKey>
    <Prefix/>
    <KeyFragment ref="CacheKey"/>
  </CacheKey>
  <CacheResource>MyCacheName</CacheResource>
  <Scope>Application</Scope>
  <AssignTo>flowVar</AssignTo>
</LookupCache>

In node:

var cache = apigeeAccess.getCache('MyCacheName', {
	                            "cache-name": "MyCacheName",
	                            "scope": "application",
	                            "defaultTtl": 10,
	                            "timeout": 30
	                          });

cache.put(cacheKey, str, 10, function (err) {
  if (err) {
    console.log('Cache put ERROR: ', err);
  }
  else {
    console.log('Added to cache');
  }
});

If we try to retrieve the object from node we hit the cache.

Solved Solved
3 5 1,096
1 ACCEPTED SOLUTION

Hi @michaelskarum

Welcome to the community !!!

You can update your above node code to something like this

var scache = apigee.getCache('MyCacheName',
                  {
                    resource: 'MyCacheName', 
                    scope:'application'
                  });
    scache.put('cacheKey', str, 3600, function(err) {
        if (err) {
	        console.log('Cache put ERROR: ', err);
	    }
	  else {
	  console.log('Added to cache');
	  }
    });  

and in the Lookup policy change

<KeyFragment ref="CacheKey"/>

to

<KeyFragment>cacheKey</KeyFragment>

Make sure the KeyFragment and the first argument in the put method matches.

Hope this helps. If you need more info, please let us know.

If this worked, please Accept the answer.

View solution in original post

5 REPLIES 5

Even I got the same when I tried

Hi @michaelskarum

Welcome to the community !!!

You can update your above node code to something like this

var scache = apigee.getCache('MyCacheName',
                  {
                    resource: 'MyCacheName', 
                    scope:'application'
                  });
    scache.put('cacheKey', str, 3600, function(err) {
        if (err) {
	        console.log('Cache put ERROR: ', err);
	    }
	  else {
	  console.log('Added to cache');
	  }
    });  

and in the Lookup policy change

<KeyFragment ref="CacheKey"/>

to

<KeyFragment>cacheKey</KeyFragment>

Make sure the KeyFragment and the first argument in the put method matches.

Hope this helps. If you need more info, please let us know.

If this worked, please Accept the answer.

Not applicable

There is a known bug in the trace tool UI where cacheHit will display as false even though the value was successfully retrieved from cache. Can you see if you are encountering that issue here? Just try to access the variable immediately after the lookup cache policy is executed. If it's the UI bug you'll be able to access the value from cache with no issue even though the UI shows a cache miss.


Update: 2020 June 2

ref: b/111777025

The fix for this issue is a bit tricky, and the team is considering the options.
We believe the common experience of people is that the Trace is misleading (wrong), but the behavior of the runtime is correct: the Cache actually works. As Chris described.

If you're still being affected by this, check Chris's suggestion, and if you still believe it's important to fix this bug, you can raise a support ticket with Apigee support, and they'll register your interest in this fix and be able to give you updates on the progress on this bug.

Hi @Sai Saran Vaidyanathan/ @clatimer1

I am still facing same issue on Edge on-premise v19.0.01.

Even I am able to retrieve cache from Lookup cache but in Edge UI trace will populate the

lookupcache.LC-LookAccessToken.cachehit value as false instead of true.

Any update on bug fix for above issue.

Hareesh, see the update above. I'm sorry about the delay in resolving this issue.