【问题标题】:Can Azure API management cached based on request payload?Azure API 管理是否可以基于请求有效负载进行缓存?
【发布时间】:2021-12-21 06:11:36
【问题描述】:

是否可以根据请求负载中的键使用缓存?

例如。假设我们有一个 json 或 xml 请求有效负载,其中一个元素是 CustomerId。

那么是否可以根据 CustomerId 进行缓存?

谢谢

【问题讨论】:

    标签: azure caching azure-api-management


    【解决方案1】:

    是的,可以根据请求负载缓存CustomerId

    谢谢BKA。发布您的建议作为帮助其他社区成员的答案。

    您可以将CustomeId 存储为JObject,然后提取“id”字段。稍后将其转换为字符串以存储在缓存中。

    <policies>
    <inbound>
        <base />
        <set-variable name="validationResults" value="@(context.Request.Body.As<JObject>())" />
        <set-variable name="CustomerId" value="@((string)((JObject)context.Variables["validationResults"])["id"])" />
        <set-variable name="payload" value="@((string)((JObject)context.Variables["validationResults"]).ToString())" />
        <cache-store-value key="@((string)context.Variables["CustomerId"])" value="@((string)context.Variables["payload"])" duration="30" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
    

    可以参考How to store JSON Payload using Azure API Manager cache-store-value policy?Add caching to improve performance in Azure API Management

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 1970-01-01
      相关资源
      最近更新 更多