Using Response Cache & Invalidate Cache Policy Together?

Hi there,

The documentation around caching does not explicitly mention whether you can use Invalidate Cache Policy with Response Cache Policy as part of a reverse proxy. It suggests you should use invalidate cache with populate and lookup.
https://docs.apigee.com/api-platform/reference/policies/response-cache-policy?hl=en 

I wish to invalidate the cache when there is a POST or DELETE request with 200 response (which can be configured as a conditional as part of the Step). Otherwise, Response Cache fulfills all my caching needs. 

Are the two Policies incompatible or is there a downside to using Response Cache with Invalidate Cache?

Thank you.

0 4 489
4 REPLIES 4

As you note the InvalidateCache policy is designed to work with the PopulateCache / LookupCache tandem.

For the response cache, you can skip the cache lookup and thereby effect a refresh by using the SkipCacheLookup condition as documented here.

Note the following quote from the documentation: 

The optional SkipCacheLookup condition (if configured) is evaluated in the request path. If the condition evaluates to true, then the cache look up is skipped and the cache is refreshed.

A common use of conditional cache refresh is a condition that defines a specific HTTP header that causes the condition to evaluate to true. A scripted client application could be configured to periodically submit a request with the appropriate HTTP header, explicitly causing the response cache to refresh.

The documentation example shows how to configure a client header that will force this bypass:

<ResponseCache name="ResponseCache">
   
<CacheKey>
       
<KeyFragment ref="request.queryparam.w" />
   
</CacheKey>
   
<!-- Explicitly refresh the cached response -->
   
<SkipCacheLookup>request.header.bypass-cache = "true"</SkipCacheLookup>
   
<ExpirySettings>
       
<TimeoutInSeconds>600</TimeoutInSeconds>
   
</ExpirySettings>
</ResponseCache>

Thanks @mw970 for your answer. So while its designed this way, I am still able to use the mixture of cache policies?

Thanks re: bypass-cache. I have now included this in my policy. 

Hi @jaycrowww , sure, nothing about the ResponseCache bypass prevents your team from utilizing a mixture of cache policies in your workflow, including the LookupCache/PopulateCache/InvalidateCache as might be appropriate. Your team can select the caching policy design that best meets your use case. Please do be mindful of cache-internals documentation to understand the operational constraints of this persistence mechanism.

Thanks for clarifying @mw970 !