azure-application-insights - 如何在 Azure API 管理中测试缓存策略
问题描述
我已向 api 路由添加了缓存存储和缓存查找策略,缓存存储在 Cache-Control 标头中的 max-age 指令中指示的持续时间。这是政策:
<inbound>
<base />
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" must-revalidate="true" downstream-caching-type="public">
<vary-by-header>Accept</vary-by-header>
<vary-by-header>Accept-Charset</vary-by-header>
<vary-by-header>Authorization</vary-by-header>
</cache-lookup>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<set-variable name="max-age" value="@{
var header = context.Response.Headers.GetValueOrDefault("Cache-Control","");
var maxAge = Regex.Match(header, @"max-age=(?<maxAge>\d+)").Groups["maxAge"]?.Value;
return (!string.IsNullOrEmpty(maxAge))?int.Parse(maxAge):0;
}" />
<choose>
<when condition="@((int)context.Variables["max-age"] > 0)">
<cache-store duration="@((int)context.Variables["max-age"])" />
</when>
</choose>
</outbound>
我尝试频繁调用路由,但在 Application Insights 的请求日志中,我没有发现响应已被缓存的迹象。customDimensions.Cache
始终设置为“无”。
编辑:我通过使缓存持续时间相对较长并比较后端记录的请求数量来测试缓存,但缓存命中的数量不是确定性的。
解决方案
推荐阅读
- mongodb - MongoDB Scala 驱动程序 - 设置字段的问题
- python - 在 Python 中,“调用函数的主要部分”是什么?
- swift - Firebase 实时数据,如何将 .child 更改为用户输入的文本字段值
- c# - avalon 编辑器中的工具提示位置
- html - 如何避免 iphone 的引导输入字段上的额外边框顶部厚度?
- automated-tests - 如何使用谷歌浏览器在无头模式下运行 botium-cli
- laravel - 与用户 laravel 的特许经营/分支机构关系
- php - INNER JOIN 与多个表
- reactjs - 从外部文件导入路由时,Rect Js路由器停止
- redis - HA redis 解决方案,集群或哨兵