|
1 | 1 | ---
|
2 |
| -title: Add caching to improve performance in Azure API Management | Microsoft Docs |
| 2 | +title: Add caching to improve performance in Azure API Management |
3 | 3 | description: Learn how to improve the latency, bandwidth consumption, and web service load for API Management service calls.
|
4 | 4 | author: dlepow
|
5 |
| -manager: erikre |
6 |
| -ms.assetid: 740f6a27-8323-474d-ade2-828ae0c75e7a |
7 | 5 | ms.service: azure-api-management
|
8 |
| -ms.topic: conceptual |
| 6 | +ms.topic: how-to |
9 | 7 | ms.date: 03/20/2024
|
10 | 8 | ms.author: danlep
|
11 | 9 | ---
|
@@ -42,52 +40,53 @@ To complete this tutorial:
|
42 | 40 | + [Create an Azure API Management instance](get-started-create-service-instance.md)
|
43 | 41 | + [Import and publish an API](import-and-publish.md)
|
44 | 42 |
|
45 |
| -## <a name="caching-policies"> </a>Add the caching policies |
| 43 | +## Add the caching policies |
46 | 44 |
|
47 |
| -With caching policies shown in this example, the first request to the **GetSpeakers** operation returns a response from the backend service. This response is cached, keyed by the specified headers and query string parameters. Subsequent calls to the operation, with matching parameters, will have the cached response returned, until the cache duration interval has expired. |
| 45 | +With caching policies shown in this example, the first request to a test operation returns a response from the backend service. This response is cached, keyed by the specified headers and query string parameters. Subsequent calls to the operation, with matching parameters, will have the cached response returned, until the cache duration interval has expired. |
48 | 46 |
|
49 | 47 | 1. Sign in to the [Azure portal](https://portal.azure.com).
|
50 |
| -2. Browse to your APIM instance. |
51 |
| -3. Select the **API** tab. |
52 |
| -4. Click **Demo Conference API** from your API list. |
53 |
| -5. Select **GetSpeakers**. |
54 |
| -6. On the top of the screen, select **Design** tab. |
55 |
| -7. In the **Inbound processing** section, click the **</>** icon. |
| 48 | +1. Browse to your API Management instance. |
| 49 | +1. Select **APIs** > **APIs** from the menu on the left. |
| 50 | +1. Select an API for which you want to configure caching. |
| 51 | +1. On the top of the screen, select **Design** tab. |
| 52 | +1. In the **Inbound processing** section, select the **</>** icon. |
| 53 | + :::image type="content" source="media/api-management-howto-cache/code-editor.png" alt-text="Screenshot of the API Management policy editor in the portal."::: |
56 | 54 |
|
57 |
| -  |
| 55 | +8. In the `inbound` element, add the following policy: |
58 | 56 |
|
59 |
| -8. In the **inbound** element, add the following policy: |
60 |
| - |
61 |
| - ``` |
| 57 | + ```xml |
62 | 58 | <cache-lookup vary-by-developer="false" vary-by-developer-groups="false">
|
63 | 59 | <vary-by-header>Accept</vary-by-header>
|
64 | 60 | <vary-by-header>Accept-Charset</vary-by-header>
|
65 | 61 | <vary-by-header>Authorization</vary-by-header>
|
66 | 62 | </cache-lookup>
|
67 | 63 | ```
|
68 | 64 |
|
69 |
| -9. In the **outbound** element, add the following policy: |
| 65 | +9. In the `outbound` element, add the following policy: |
70 | 66 |
|
71 |
| - ``` |
| 67 | + ```xml |
72 | 68 | <cache-store duration="20" />
|
73 | 69 | ```
|
74 | 70 |
|
75 |
| - **Duration** specifies the expiration interval of the cached responses. In this example, the interval is **20** seconds. |
| 71 | + In this policy, **duration** specifies the expiration interval of the cached responses. In this example, the interval is **20** seconds. |
76 | 72 |
|
77 | 73 | > [!TIP]
|
78 | 74 | > If you are using an external cache, as described in [Use an external Azure Cache for Redis in Azure API Management](api-management-howto-cache-external.md), you may want to specify the `caching-type` attribute of the caching policies. See [API Management caching policies](api-management-policies.md#caching) for more details.
|
79 | 75 |
|
80 |
| -## <a name="test-operation"> </a>Call an operation and test the caching |
81 |
| -To see the caching in action, call the operation from the developer portal. |
| 76 | +## Call an operation and test the caching |
| 77 | +To see the caching in action, call an operation from the portal. |
82 | 78 |
|
83 |
| -1. In the Azure portal, browse to your APIM instance. |
84 |
| -2. Select the **APIs** tab. |
85 |
| -3. Select the API to which you added caching policies. |
86 |
| -4. Select the **GetSpeakers** operation. |
87 |
| -5. Click the **Test** tab in the top right menu. |
88 |
| -6. Press **Send**. |
| 79 | +1. In the Azure portal, browse to your API Management instance. |
| 80 | +1. Select **APIs** > **APIs** from the menu on the left. |
| 81 | +1. Select the API to which you added caching policies. |
| 82 | +1. Select an operation to test. |
| 83 | +1. Select the **Test** tab in the top right menu. |
| 84 | +1. Select **Trace** two or three times in quick succession. |
| 85 | +1. Under **HTTP response**, select the **Trace** tab. |
| 86 | +1. Jump to the **Inbound** section and scroll to the `cache-lookup` policy. You should see a message similar to the one in the following screenshot, indicating a cache hit: |
| 87 | + :::image type="content" source="media/api-management-howto-cache/test-api-cache-lookup.png" alt-text="Screenshot of cache-lookup when testing an API in the portal."::: |
89 | 88 |
|
90 |
| -## <a name="next-steps"> </a>Next steps |
| 89 | +## Related content |
91 | 90 | * For more information about caching policies, see [Caching policies][Caching policies] in the [API Management policy reference][API Management policy reference].
|
92 | 91 | * For information on caching items by key using policy expressions, see [Custom caching in Azure API Management](api-management-sample-cache-by-key.md).
|
93 | 92 | * For more information about using external Azure Cache for Redis, see [Use an external Azure Cache for Redis in Azure API Management](api-management-howto-cache-external.md).
|
@@ -116,7 +115,4 @@ To see the caching in action, call the operation from the developer portal.
|
116 | 115 |
|
117 | 116 | [Create an API Management service instance]: get-started-create-service-instance.md
|
118 | 117 |
|
119 |
| -[Configure an operation for caching]: #configure-caching |
120 |
| -[Review the caching policies]: #caching-policies |
121 |
| -[Call an operation and test the caching]: #test-operation |
122 |
| -[Next steps]: #next-steps |
| 118 | + |
0 commit comments