Invalidate response cache from node.js using apigee-access

Hi community,

I am trying to invalidate a cache item that I cached using ResponseCache policy with node.js apigee-access.

Here is the policy:

<ResponseCache name="Response-Cache-1">
    <CacheKey>
        <KeyFragment ref="request.uri" type="string"/>
    </CacheKey>
  <CacheResource>my-cache-resource</CacheResource>
    <Scope>Global</Scope>
    <ExpirySettings>
        <TimeoutInSec>3600</TimeoutInSec>
    </ExpirySettings>
</ResponseCache>

I am looking at the apigee-access cache documentation: http://apigee.com/docs/api-services/content/access-cache-nodejs

According to this, in order to remove a cache item, I am doing this:

var cache = apigee.getCache(cacheName, {
  resource: 'my-cache-resource',
  scope: 'global'
});
  
cache.remove(key, function(err) {

I am getting the values for key and cacheName from trace:

key: oseymen__test____/cache-invalidation/cachethis/a

cacheName: oseymen__test__my-cache-resource

Unfortunately I am unable to remove the cache item - consecutive requests still get returned from response cache. I can see it in trace.

Is this not supported or am I doing something wrong?

Cheers

Ozan

Solved Solved
0 5 613
1 ACCEPTED SOLUTION

Got it...

First of all cacheName is useless in this scenario. It doesn't change the behaviour and it still works even if you set it to some random string.

Second is that the key shouldn't contain the org and env in the beginning. So this key will work for the above example:

key: /cache-invalidation/cachethis/a

We might make this clearer in the documentation.

View solution in original post

5 REPLIES 5

Got it...

First of all cacheName is useless in this scenario. It doesn't change the behaviour and it still works even if you set it to some random string.

Second is that the key shouldn't contain the org and env in the beginning. So this key will work for the above example:

key: /cache-invalidation/cachethis/a

We might make this clearer in the documentation.

I've just sent feedback for the docs to make the section about key construction clearer.

Thanks, Ozan. The docs on accessing the cache from Node have bee updated with a note about using scope-related cache key strings.

http://apigee.com/docs/api-services/content/access-cache-nodejs

Steve

The documentation still isn't clear. It doesn't clarify the difference between cache-name and cache-resource. Cache name isn't mentioned in the Policy documentation - only in the Node documentation. And the contents of the cache name doesn't seem to matter - you can put anything in there - which begs the question - what is it there for?