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
Dear @Girish Gajria,
As per the documentation
here, you need to set the <UseResponseCacheHeaders>
element value to true to be able to use the response headers "Cache-Control" and "Expires". Your comment in the Cache policy about this tag states "This does not work as expected". Not sure what your experiments were about this tag.
Anyways, I would like to check the following:
Have you tried setting <UseResponseCacheHeaders>
to true ? If not, can you please set it to true and check the behaviour ?
Note: The element<UseResponseCacheHeaders>
is false by default.
Regards,
Amar
You might want to read the following document - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
There are a bunch of Cache-Control values that the client can send in a HTTP request. For example 'max-age', 'max-stale'. Therefore instead of checking for:
request.header.Cache-Control = "no-cache"
You may need to use a Javascript callout to find the 'no-cache' value from the list of Cache-Control headers.
User | Count |
---|---|
7 | |
2 | |
2 | |
2 | |
1 |