我们正在使用<cache-lookup>
政策<inbound>
block (带有外部 Redis)。是否可以执行一项政策 - 具体来说,我想写一个 <trace>
当缓存查找命中并且从缓存提供响应时?
今天我们有这个:
<inbound>
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none" caching-type="external">
<vary-by-query-parameter>xyz</vary-by-query-parameter>
</cache-lookup>
这样的事情可能吗? (伪代码)
<choose>
<when condition="cache-lookup == true">
<trace>
<message>This request is served from Redis cache!</message>
</trace>
</when>
</choose>
</inbound>
最佳答案
根据一些研究,似乎没有一个变量或状态可供我们判断请求是从 Redis 缓存还是后端服务器提供的。 <cache-lookup>
策略包装了与 Redis 连接的功能,我认为我们无法知道请求是从哪里提供的。正如您提到的代码是伪代码,我不认为代码 <when condition="cache-lookup == true">
可以工作。
对于这个需求,我想你可以向azure开发团队询问此功能feedback页。
关于Azure API 管理 - 确定是否从缓存提供响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65422557/