Azure / api-management-policy-snippets

Re-usable examples of Azure API Management policies
MIT License
341 stars 155 forks source link

Aren't APIM's inbound policies able to read Redis Cache keys set externally? #115

Open eugen-nw opened 11 months ago

eugen-nw commented 11 months ago

We have a customer in West Europe and am setting up an APIM instance for them in the Central France region. We're running the REST API and the backend in West US. It takes ~20 seconds for a ~2MB file to travel from West US to Central France. In order to improve that delay, I'm attempting to write the file into a Redis instance that's located in Central France and have APIM's inbound policy read it from Redis and return it right away if present, instead of calling our West US located REST API. I could not get this to work, so am wondering what am I missing or is such a scenario not supported by APIM? A key in Redis is key in Redis and should be readable by any service that has access rights to the Redis instance.

I set the APIM's Managed Identity to have "Redis Contributor" permissions on the Redis instance.

I did find earlier #43 and am caching in the backend using the "2" prefixed key and lookup in APIM's inbound policy using the bare key. It does not work. I did use VS Code's Azure Cache extension to verify that the "2" prefixed key is present in the Redis cache. image

I did add the two highlighted cache operations and do notice in the test call's trace that both are successful. This shows that APIM's policy can use the Redis instance. image image

tomkerkhove commented 11 months ago

Adding @akamenev but as far as I know, we only allow getting APIM-managed cache keys.

eugen-nw commented 11 months ago

That’d be quite unfortunate. As I am warming up the cache externally, I am setting up the very first call to be fast to return a result. Perhaps a feature for APIM to consider for the future?