Soru

Zorluk: ZorDefine API Management Policies

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?

  1. 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
  2. Add the following policy inside the <outbound> section:
    <cache-store duration="300" condition="@(context.Response.Headers.GetValueOrDefault('X-Cache-Private', '') != 'true')" />
    Cevap
  3. C
    Add the following policy inside the <inbound> section:
    <cache-store duration="300" condition="@(context.Response.Headers.GetValueOrDefault('X-Cache-Private', '') != 'true')" />
  4. D
    Add 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

1
Place the <cache-lookup> policy in the <inbound> policy section.
This enables checking the API Management cache before sending the request to the backend service.
Looking up cached responses must happen during inbound processing to avoid forwarding the request to the backend if a cache hit occurs.
2
Configure the vary-by criteria in <cache-lookup>.
Add <vary-by-header>Accept-Language</vary-by-header> and <vary-by-query-parameter>city</vary-by-query-parameter> children to <cache-lookup>.
This ensures that API Management caches distinct responses for different language preferences and city requests.
3
Place the <cache-store> policy in the <outbound> policy section.
This enables caching backend responses as they return through the outbound pipeline.
Storing response content in the cache requires access to the response headers and body, which are only available in the outbound processing pipeline.
4
Configure the duration and conditional caching on <cache-store>.
Set duration to 300 and use a policy expression condition checking that the X-Cache-Private header value is not 'true'.
This guarantees that responses are stored for the requested 300 seconds and prevents sensitive data from being cached based on the backend response headers.

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.
Bu soruyu puanla