I have a target server that may return 404. We would like to cache that 404 response for a short period of time, to reduce the calls to target. This particular target has an "expensive" resource lookup, so it is desirable to not make the outgoing call to target for the same Not Found resource over and over again.
I have added my ResponseCache policy to the TargetEndpoint's FaultRules, as:
<FaultRules> <FaultRule name="origin_error_response"> <Step> <Name>RCC3MediaResponseCache</Name> <Condition>(my.responseCache.ttl > 0) and (proxy.pathsuffix MatchesPath "/media**")</Condition> </Step> <Condition>fault.name == "ErrorResponseCode"</Condition> </FaultRule> </FaultRules>
I have also modified my ResponseCache policy to have:
<ExcludeErrorResponse>false</ExcludeErrorResponse>
and declared the SkipPopulation as:
<SkipCachePopulation>(request.verb != "GET")</SkipCachePopulation>
For completeness, here is the ResponseCache policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ResponseCache async="false" continueOnError="false" enabled="true" name="RCC3MediaResponseCache"> <DisplayName>RCC3MediaResponseCache</DisplayName> <Properties/> <CacheResource>media_responseCache</CacheResource> <CacheKey> <KeyFragment ref="my.cacheKey" type="string"/> </CacheKey> <Scope>Exclusive</Scope> <ExpirySettings> <TimeoutInSec ref="my.responseCache.ttl"/> </ExpirySettings> <!-- This has to be false to allow us to cache non-2xx responses --> <ExcludeErrorResponse>false</ExcludeErrorResponse> <UseAcceptHeader>false</UseAcceptHeader> <UseResponseCacheHeaders>true</UseResponseCacheHeaders> <SkipCacheLookup>request.verb != "GET"</SkipCacheLookup> <SkipCachePopulation>(request.verb != "GET")</SkipCachePopulation> </ResponseCache>
Note that this ResponseCache policy works as expected in the ProxyEndpoint's PreFlow/PostFlow as per normal ResponseCache practice, when there is NOT a fault of "ErrorResponse".
With Trace, I can see that the ResponseCache is being executed in the ProxyEndpoint's PreFlow, as well as in the TargetEndpoint's fault processing. However, if I make the same GET call a second time, the ResponseCache policy called in the ProxyEndpoint's PreFlow indicates cachehit=false.
Is there some restriction that would prevent the ResponseCache from populating the cache during fault processing, other than the obvious ExcludeErrorResponse and SkipCachePopulation settings within the RC policy?