简体   繁体   中英

Azure API Management caching does not work with error "Request is not cacheable, policy was not applied."

I'm sure I am missing something, but I couldn't find out what it was... I have set up an Azure API Management (consumption plan) API that calls a remote API endpoint and I want to enable caching. The payload almost never changes, so I'm sure caching makes sense here.

This is the policy I have:

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="https://xxxapixxx.azurewebsites.net/api" />
        <rewrite-uri template="segments" copy-unmatched-params="true" />
        <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none">
            <vary-by-header>Accept</vary-by-header>
            <vary-by-header>Accept-Charset</vary-by-header>
        </cache-lookup>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
        <cache-store duration="7200" />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

When I test the call in the portal, I see two Trace messages, related to the caching policy:

In the inbound trace:

cache-lookup (0.012 ms) "No appropriate cache found for provided policy configuration. Policy execution will be skipped."

In the outbound trace:

cache-store (0.026 ms) "Request is not cacheable, policy was not applied."

I am guessing it has to do with the gzip compression, but still cannot see how to fix it.

Any guesses, ideas ?

According to the Microsoft document , I assume your pricing tier results in this problem .

The ducument says:

Internal cache is not available in the Consumption tier of Azure API Management. You can use an external Azure Cache for Redis instead. 在此处输入图片说明

So I created two Apim instance, one is developer,another is consumption. They all use the same policy but have different response. The developer one can use cach but the consumption one returns the same response as yours.

Here's the detail. 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM