基于查询参数的APIM缓存



我正在开发Azure APIM。我有一个端点如下。以QueryParam作为输入。我想缓存2分钟(如果QueryParam相同)。

为了缓存2分钟。我必须使用outbound=>缓存存储持续时间但未找到任何示例"如何检查查询参数">

<policies>
<inbound>
<base />
</inbound>
<outbound>
<cache-store duration="seconds" />
<base />
</outbound>
</policies>
[HTTPGET]
Public GetProduct(QueryParam param) 
{
}
Class QueryParam {
String productCode {get;set;}
DateTime PurchasedDate {get;set;}
}

来自Microsoft文档的示例:

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

使用vary-by查询参数时,您可能需要在rewrite-uri模板中声明参数,或者将属性副本不匹配的params设置为false。通过停用此标志,未声明的参数将被发送到后端。

政策声明

<cache-lookup vary-by-developer="true | false" vary-by-developer-groups="true | false" caching-type="prefer-external | external | internal" downstream-caching-type="none | private | public" must-revalidate="true | false" allow-private-response-caching="@(expression to evaluate)">
<vary-by-query-parameter>parameter name</vary-by-query-parameter>
<!-- optional, can repeated several times -->
</cache-lookup>

最新更新