After reading the documentation here, came across the setting UseResponseCacheHeaders. If I understand this right, if I set the appropriate Cache-Control header and Expires header, the cache will honor the value set here and expire the resource accordingly. But this is not working as expected.
On the Target PostFlow Response, I set the headers by means of a JavaScript policy, below is the code:
var now = new Date().getTime();
var ttl = 10 * 1000;
var then = now + ttl;
var thenDate = new Date(then);
context.setVariable("response.header.Expires",thenDate.toUTCString());
context.setVariable("response.header.Cache-Control","max-age="+ttl);
The ResponseCachePolicy is attached at the Response of one of my Flows as below, including the policy XML as well:
Proxy Flow XML:
<Flow name="getCache">
<Description/>
<Condition>request.verb = "GET" AND proxy.pathsuffix MatchesPath "/getCache"</Condition>
<Request>
<Step>
<Name>ResponseCache</Name>
</Step>
</Request>
<Response>
<Step>
<Name>ResponseCache</Name>
<Condition>response.status.code = 200</Condition>
</Step>
</Response>
</Flow>
Cache Policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="ResponseCache">
<DisplayName>ResponseCache</DisplayName>
<Properties/>
<CacheKey>
<KeyFragment>getCache</KeyFragment> <!-- hard coded flow identifier -->
<KeyFragment ref="accesstoken.attribute1"/>
<KeyFragment ref="accesstoken.attribute2"/>
</CacheKey>
<Scope>Global</Scope>
<CacheResource>cache-resource</CacheResource>
<!--ExpirySettings>
<TimeoutInSec ref="">3600</TimeoutInSec>
</ExpirySettings--> <!-- tried commenting/uncommenting this -->
<SkipCacheLookup>request.header.Cache-Control = "no-cache"</SkipCacheLookup> <!-- this works as expected and by passes the cache and hits the target -->
<SkipCachePopulation/>
<UseResponseCacheHeaders/> <!-- This does not work as expected -->
</ResponseCache>
Any thoughts/suggestions appreciated.
Thanks,
Girish