Search code examples
azure-api-managementazure-redis-cache

Azure Redis Cache with API Management


I have set up an Azure Redis cache to use with APIM.

I know it doesn't make sense to cache 'Post' methods but can I put a policy at the root level of APIM and is it smart enough to cache the relevant get methods without me having to apply the policy at the individual method level?

Also - will it produce any weird behavior by attempting to cache Post requests?

My policy is

<policies>
    <inbound>
        <base />
        <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none" caching-type="external" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
        <cache-store duration="3600" />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Solution

  • Azure API Management seems to be smart enough to only cache the relevant HTTP methods. If you put the caching policy at the root level, and attempt to test a POST method, the policy trace gives a message like below:

    "cache-lookup (0.081 ms) "Request has a non-cacheable HTTP method. Cache Lookup policy was not applied.""