4

In APIM is it possible to proactively invalidate and refresh the cache using a policy, so that users never experience a cache miss and the latest data is populated in the cache? We have a request that's taking awhile to come back, so we never want to have the client wait for it.

There's a request to invalidate the cache based on post/put operations, which would be perfect: https://feedback.azure.com/forums/248703-api-management/suggestions/13428855-invalidate-cache-based-on-other-operations

Unfortunately, it's 2 years old and still under review.

1 Answer 1

1

Use custom caching to store and update value. You can use Azure functions to schedule a timer to call an api in APIM for updating cache.

https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-cache-by-key

Sign up to request clarification or add additional context in comments.

6 Comments

That would work if the cache uses a sliding expiration instead of absolute. Do you know if that's the case with APIM?
Actually if it were sliding expiration the cache would never get updated if it were paired with a timer that called it before it expires, right? We would need a way to invalidate the cache as well.
cache-store-value policy works by absolute expiration time. You will have to use cache-remove-value policy to remove cache for invalidation. Steps 1. Timer pings api - refreshCache every 4 mins. 2. refreshCache api uses cache-store-value policy to update all keys, duration 5 mins. 3. If POST/PUT calls happen which requires cache invalidation. A policy can be added for those operations to update (refresh) or remove cache keys.
Thanks, JJ I'll give this a try.
@JoeyEng how did you solve this finally?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.