Skip Cache if the input has been changed

Hi,

How can i skip the cache if the input request has been changed.

{
  "Id""001",
  "Data""D1"
}
 
So let's say if we have pass another input request as well.
 
{
  "Id""002",
  "Data""D2"
}
 
still i am getting old value from cache. i am expecting the new value based on "Id": "002".
 
I have used ResponseCache for my cache.
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache continueOnError="false" enabled="true" name="RC-DSInfo">
<DisplayName>RC-Profile Cache</DisplayName>
<Properties/>
<CacheKey>
<Prefix/>
<KeyFragment>response</KeyFragment>
</CacheKey>
<Scope>Exclusive</Scope>
<ExpirySettings>
<ExpiryDate/>
<TimeOfDay/>
<TimeoutInSec ref="">300</TimeoutInSec>
</ExpirySettings>
<Source>response.content</Source>
<SkipCacheLookup></SkipCacheLookup>
</ResponseCache>
 
Solved Solved
0 2 125
1 ACCEPTED SOLUTION

Seems like you are misunderstanding how the ResponseCache policy works. Please take a look at the documentation, specially how to work with cache keys.

In a nutshell, your cache keys needs to be uniquely defined and since in your case you want it to be based on the incoming JSON payload, you should consider using the Id and Data as cache keys accordingly. For example, you can have an ExtractVariable policy to set a variable:

 

<ExtractVariables name="EV-CacheKeys">
    <Source>request</Source>
    <JSONPayload>
        <Variable name="id" type="string">
            <JSONPath>$.Id</JSONPath>
        </Variable>
    </JSONPayload>
    <VariablePrefix>ck</VariablePrefix>
</ExtractVariables>

 

And then reference this variable as your cache key fragment in the ResponseCache policy:

 

<ResponseCache continueOnError="false" enabled="true" name="RC-Test">
    <DisplayName>RC-Test</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix/>
        <KeyFragment ref="ck.id"/>
    </CacheKey>
    <Scope>Exclusive</Scope>
    <ExpirySettings>
        <ExpiryDate/>
        <TimeOfDay/>
        <TimeoutInSec ref="">3600</TimeoutInSec>
    </ExpirySettings>
    <SkipCacheLookup/>
    <SkipCachePopulation/>
</ResponseCache>

 

I hope this helps!

View solution in original post

2 REPLIES 2

Seems like you are misunderstanding how the ResponseCache policy works. Please take a look at the documentation, specially how to work with cache keys.

In a nutshell, your cache keys needs to be uniquely defined and since in your case you want it to be based on the incoming JSON payload, you should consider using the Id and Data as cache keys accordingly. For example, you can have an ExtractVariable policy to set a variable:

 

<ExtractVariables name="EV-CacheKeys">
    <Source>request</Source>
    <JSONPayload>
        <Variable name="id" type="string">
            <JSONPath>$.Id</JSONPath>
        </Variable>
    </JSONPayload>
    <VariablePrefix>ck</VariablePrefix>
</ExtractVariables>

 

And then reference this variable as your cache key fragment in the ResponseCache policy:

 

<ResponseCache continueOnError="false" enabled="true" name="RC-Test">
    <DisplayName>RC-Test</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix/>
        <KeyFragment ref="ck.id"/>
    </CacheKey>
    <Scope>Exclusive</Scope>
    <ExpirySettings>
        <ExpiryDate/>
        <TimeOfDay/>
        <TimeoutInSec ref="">3600</TimeoutInSec>
    </ExpirySettings>
    <SkipCacheLookup/>
    <SkipCachePopulation/>
</ResponseCache>

 

I hope this helps!

@pablosan Thanks for help. It worked.