Managing built-in cache in Azure API Management
Azure API Management offers caching possibilities to improve performance.
There are 2 caching options:
- Response Caching - Useful for caching entire HTTP responses
- Value Caching - To cache arbitrary pieces of data from within policy definitions.
- Built-in cache
- External Redis Compatible cache
Typically, Value storage is used for fragment caching - where responses contain data that is expensive to determine and yet remains fresh for a reasonable amount of time. Also, within the APIM policies, we want to cache certain values e.g. OAuth tokens, key-vault secrets, etc. because these remain relatively fresh for a longer period of time.
With caching comes the need to manage the cache specially when you need to clear cached values because they are stale.
In some scenarios, where OAuth tokens or secrets are cached, you can create a fallback scenario that when authN fails, the cache for the key is purged and a new token is obtained or a fresh read from the key-vault is forced. In addition, there might be other such cached values that might need immediate purging in the cache.
With external Redis Compatible Caches, this is a simple task. We can use the Redis Console and issue a "del" command to immediately purge a key and its value from the cache.
However, there is no such interface when it comes to the in-built cache. All interactions with the in-built cache take place through the APIM policies.
Since the in-built cache is shared by all units in the same region in the same API Management instance, we can create a API that works as a Cache Management Endpoint for that instance.
First let us look at the traces generated by APIM when we call an API that caches a value.
Policy for our sample API
Scenario: Cache not set
e.g. Invoke-WebRequest -Uri https://<<your apim url>>/managecache/clearkey?key=<<mykey>>
Thank you so much for this nice information.
ReplyDeleteText Analytics Software
Text Analytics Tool
Text Extraction Tool
Text Classification Tool
Text Summarization Tool
This post gave me a lot of information on this topic. Keep it up and keep sharing this type of information with us. Try to explore our services towards digital transformation.
ReplyDeletePredictive Analytics Services
Big Data Engineering Solutions
Machine Learning (ML) Services