gpt4 book ai didi

Azure API 管理可选缓存

转载 作者:行者123 更新时间:2023-12-03 06:17:12 25 4
gpt4 key购买 nike

主要问题是我想使用 Azure APIM 进行可选缓存。使用缓存的主要原因是为了提高性能。另外,仍然想通过使用 header 来控制缓存选项和持续时间。默认情况下没有缓存。缓存对于客户来说应该是可选的。

我尝试过使用cache-lookup-value,因为它使您能够通过键进行缓存,并且还计划使用 token 值来实现可选的缓存功能。但我发现使用上述 cache-lookup-value 会导致性能下降。

是否有另一种方法/解决方法选项可以做得更好?也许还可以使用 Redis?谢谢

最佳答案

  • 是的,正如您所说,要使用 Azure APIM 启用可选缓存,您可以使用缓存查找策略。它允许您根据指定的 header 或查询参数缓存响应。
  • 如果您想存储回复,您还可以使用 cache-store policy将响应存储在缓存中。
  • 如果您在使用缓存查找值策略时遇到性能下降问题,那么您可以使用外部缓存,例如 Redis。这将使您能够减轻 APIM 的缓存工作负载并提高性能。MS 文档 Use an external Redis提供以下详细信息。

Using an external cache enables you to get around some of the built-incache's restrictions:

  • Avoid periodic cache clearing during API Management upgrades.
  • additional flexibility in cache configuration
  • Cache more information than the API Management layer permits.
  • 按照上述文档创建了 Azure Redis 缓存,并在此使用 Schedule updates您可以控制一周中的日期和时间,如下图所示。转到已创建的 Azure Redis 缓存 >> 设置 >> 计划更新。

enter image description here

  • 您还可以在 APIM 中创建外部缓存,如下所示:转到创建的 API 管理服务 >> 外部缓存 >> + 添加。 enter image description here您还可以引用这些Custom caching持续时间相关信息和 MS document了解更多信息。

关于Azure API 管理可选缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76127991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com