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

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 750
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
Top Solution Authors