You are configuring caching policies in Azure API Management (APIM) for a weather forecast API to reduce backend load. The API has the following requirements:
- Cache successful backend responses for 300 seconds.
- Vary the cached responses based on the HTTP header named 'Accept-Language' and the query parameter named 'city'.
- Prevent caching of responses that contain sensitive data, which is indicated by a custom backend response header 'X-Cache-Private: true'.
Which two of the following policy configurations must you implement to meet these requirements?
- Add the following policy inside the <inbound> section:
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none">
<vary-by-header>Accept-Language</vary-by-header>
<vary-by-query-parameter>city</vary-by-query-parameter>
</cache-lookup>Cevap - Add the following policy inside the <outbound> section:
<cache-store duration="300" condition="@(context.Response.Headers.GetValueOrDefault('X-Cache-Private', '') != 'true')" />Cevap - CAdd the following policy inside the <inbound> section:
<cache-store duration="300" condition="@(context.Response.Headers.GetValueOrDefault('X-Cache-Private', '') != 'true')" /> - DAdd the following policy inside the <outbound> section:
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" downstream-caching-type="none">
<vary-by-header>Accept-Language</vary-by-header>
<vary-by-query-parameter>city</vary-by-query-parameter>
</cache-lookup>
Cevap
Configure the cache-lookup policy within the inbound section to vary by the Accept-Language header and the city query parameter, and configure the cache-store policy within the outbound section with a duration of 300 seconds and a condition checking that the X-Cache-Private header is not true.
To implement caching in Azure API Management (APIM), you must split the configuration between the inbound and outbound pipelines. The cache lookup must happen in the inbound pipeline to intercept requests and serve cached data when available. This cache lookup is configured using the <cache-lookup> policy, varying by the requested headers and parameters. The actual storing of the response must happen in the outbound pipeline via the <cache-store> policy, using a condition that dynamically inspects the backend response headers to prevent caching sensitive data.
Adım Adım Çözüm
Anahtar Kavram
Azure API Management caching policy configuration requires cache lookup to occur in the inbound section and cache storage to occur in the outbound section.