Azure API管理:缓存存储不支持持续时间



在Azure APIM中,我有一个查询SQL表的API。我为API创建了一个缓存策略,在300秒后过期。然后我创建了一个脚本,每10分钟调用API,并跟踪API响应和SQL Server db.

在将近一个小时的时间里,所有对API的调用都是缓存命中——只有两个缓存未命中记录在App Insights中(第一次调用和最后一次调用在+50分钟标记处),只有两个sql调用记录在我的sql profiler跟踪中(第一次和最后一次调用)。

我几乎每次都期待看到cache-miss,但是没有。我是否误解了cache-store?

以下是策略定义:

<policies>
<inbound>
<base />
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" must-revalidate="true" downstream-caching-type="none" caching-type="internal">
<vary-by-query-parameter>xxxxx</vary-by-query-parameter>
</cache-lookup>
</inbound>
<backend>
<base />
</backend>
<outbound>
<cache-store duration="300" />
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

请尝试修改后的出站策略:

<cache-store duration="10" cache-response="true" />

存储到缓存

cache-response:
设置为true缓存当前HTTP响应。如果省略该属性或设置为false,则只缓存状态码为200 OK的HTTP响应。

这也意味着,你必须检查你当前的响应代码200/400/404/500/…可能大多数时候都是404响应,没有缓存。

相关内容

最新更新