How to remove cache using Invalidate Cache policy based on the reference "request.uri"?

Not applicable

I am using response cache for an API proxy which fetches data from the backend data store. For the GET request it is working fine. When I change any entity in the backend store it is still fetching the old value because of this response cache. I invalidate the cache in target response flow based on the request.uri and request.verb. If request.verb is PUT I need to invalidate the cache policy as mentioned here https://community.apigee.com/questions/21128/how-to-invalidate-a-cache-entry-that-was-populated.html I am unable to deploy and I am getting this error

Invalid cache resource reference in Step definition Invalidate-Cache-1.

this is my Invalidate-cache policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvalidateCache async="false" continueOnError="false" enabled="true" name="Invalidate-Cache-1">
    <DisplayName>Invalidate Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix/>
        <KeyFragment ref="request.uri" type="string"/>
    </CacheKey>
    <CacheResource/>
    <Scope>Global</Scope>
    <CacheContext>
        <APIProxyName/>
        <ProxyName>default</ProxyName>
        <TargetName>default</TargetName>
    </CacheContext>
    <PurgeChildEntries>true</PurgeChildEntries>
</InvalidateCache>
0 3 1,932
3 REPLIES 3

Hi Chockalingam, Thanks for asking!

Invalid cache resource reference in Step definition will occur when

1) The cache specified in the <CacheResource> element does not exist.

2) The cache specified in the <CacheResource> element does not match with one used in your PopulateCache policy.

From your policy definition, i see <CacheResource/> is kept empty, and you can omit this element completely if this policy and your corresponding PopulateCache policy is using the included shared cache.

Can you please double check your populateCache policy and make sure the same <CacheResource> is also being used in InvalidateCache policy as well.

Cheers,

Vidheer.

Hi @Vidheer Gadikota thanks for replying. I removed <CacheResource> and it is getting deployed without any error. But I did not get the expected result. I am caching the GET requests using response cache policy based on request.uri <KeyFragment ref="request.uri" type="string"/> .

For GET requests, I used response caching. Whenever a successful update happens via PUT request I clear the cache using Invalidate caching policy.

When the backend data is updated I am still getting the value from cache instead of getting the updated data.

There are two responsecache.cachesource L1 and L2. The cache was not cleared in all the cachesource.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="Response-Cache-1">
    <DisplayName>Response Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix/>
        <KeyFragment ref="request.uri" type="string"/>
    </CacheKey>
    <Scope>Global</Scope>
    <ExpirySettings>
        <ExpiryDate/>
        <TimeOfDay/>
        <TimeoutInSec ref="">3600</TimeoutInSec>
    </ExpirySettings>
    <SkipCacheLookup/>
    <SkipCachePopulation/>
</ResponseCache>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvalidateCache async="false" continueOnError="false" enabled="true" name="Invalidate-Cache-1">
    <DisplayName>Invalidate Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix/>
        <KeyFragment ref="request_uri"/>
    </CacheKey>
    <Scope>Global</Scope>
    <CacheContext>
        <APIProxyName/>
        <ProxyName>default</ProxyName>
        <TargetName>default</TargetName>
    </CacheContext>
    <PurgeChildEntries>true</PurgeChildEntries>
</InvalidateCache>

In short, I am using an API proxy to get collection data from API Baas. I use response cache policy in the conditional flow (=GET) for caching. I want to clear the cache whenever an update happens in the corresponding collection data. How to achieve this? If Invalidate cache policy needs to be used also let me know in which flow it should be added.