简体   繁体   English

Azure API 管理 - 确定响应是否来自缓存

[英]Azure API Management - determine if response was served from cache

We are using a <cache-lookup> policy in the <inbound> block (with an external Redis).我们在<inbound>块中使用<cache-lookup>策略(使用外部 Redis)。 Is it possible to execute a policy - to be specific, I would like to write a <trace> when the cache lookup was a hit and the response is served from cache?是否可以执行策略 - 具体来说,我想在缓存查找成功并且响应从缓存中提供时写一个<trace>

Today we have this:今天我们有这个:

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

Is something like this possible?这样的事情可能吗? (pseudo code) (伪代码)

  <choose>
    <when condition="cache-lookup == true">
       <trace>
         <message>This request is served from Redis cache!</message>
       </trace>
    </when>
  </choose>
</inbound>

According to some research, it seems there isn't a variable or status for us to judge if the request is served from Redis cache or the backend server.根据一些研究,似乎没有变量或状态可供我们判断请求是来自 Redis 缓存还是后端服务器。 The <cache-lookup> policy wraps the functions connect with Redis, I don't think we can know where the request is served from. <cache-lookup>策略包装了与 Redis 连接的函数,我认为我们无法知道请求的来源。 And as you mentioned the code is pseudo, I don't think the code <when condition="cache-lookup == true"> can work.正如你提到的代码是伪代码,我不认为代码<when condition="cache-lookup == true">可以工作。

For this requirement, I think you can just ask azure develop team for this feature on feedback page.对于这个要求,我想你可以在反馈页面上向 azure 开发团队询问这个功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM