Azure API 管理缓存不工作并出现错误 "Request is not cacheable, policy was not applied."

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

我确定我遗漏了什么,但我找不到是什么... 我已经设置了一个调用远程 API 端点的 Azure API 管理(消费计划)API,我想启用缓存。有效载荷几乎从不改变,所以我确信缓存在这里很有意义。

这是我的政策:

<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>

当我在门户中测试调用时,我看到两条与缓存策略相关的跟踪消息:

在入站跟踪中:

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

在出站跟踪中:

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

我猜它与 gzip 压缩有关,但仍然看不出如何修复它。

有什么猜测和想法吗?

根据 Microsoft document,我认为您的 定价层会导致此问题

文档说:

Internal cache is not available in the Consumption tier of Azure API Management. You can use an external Azure Cache for Redis instead.

所以我创建了两个Apim实例,一个是开发者,一个是消费。他们都使用相同的策略,但有不同的响应。开发者可以使用缓存,但消费者 returns 与您的响应相同。

详情如下。