You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
APIs and operations in API Management can be configured with response caching. Response caching can significantly reduce latency for API callers and backend load for API providers.
17
+
APIs and operations in API Management can be configured with response caching. Response caching can significantly reduce latency for API callers and backend load for API providers.
16
18
17
19
> [!IMPORTANT]
18
-
> Built-in cache is volatile and is shared by all units in the same region in the same API Management service. Regardless of the cache type being used (internal or external), if the cache-related operations fail to connect to the cache due to the volatility of the cache or any other reason, the API call that uses the cache related operation doesn't raise an error, and the cache operation completes successfully. In the case of a read operation, a null value is returned to the calling policy expression. Your policy code should be designed to ensure that there's a "fallback" mechanism to retrieve data not found in the cache.
20
+
> Built-in cache is volatile and is shared by all units in the same region in the same API Management service. Regardless of the cache type being used (internal or external), if cache-related operations fail to connect to the cache because of the volatility of the cache or for any other reason, the API call that uses the cache-related operation doesn't raise an error, and the cache operation completes successfully. In the case of a read operation, a null value is returned to the calling policy expression. Your policy code should be designed to ensure that there's a fallback mechanism to retrieve data that's not found in the cache.
21
+
19
22
For more detailed information about caching, see [API Management caching policies](api-management-policies.md#caching) and [Custom caching in Azure API Management](api-management-sample-cache-by-key.md).
:::image type="content" source="media/api-management-howto-cache/cache-policies.png" alt-text="Screenshot that shows cache policies in API Management." lightbox="media/api-management-howto-cache/cache-policies.png":::
25
+
22
26
23
27
What you'll learn:
24
28
25
29
> [!div class="checklist"]
26
30
> * Add response caching for your API
27
-
> * Verify caching in action
31
+
> * Verify that caching is working
28
32
29
33
30
34
> [!NOTE]
31
-
> Internal cache is not available in the **Consumption** tier of Azure API Management. You can [use an external Azure Cache for Redis](api-management-howto-cache-external.md) instead. You can also configure an external cache in other API Management service tiers.
35
+
> Internal caching isn't available in the **Consumption** tier of Azure API Management. You can [use an external Azure Cache for Redis](api-management-howto-cache-external.md) instead. You can also configure an external cache in other API Management service tiers.
32
36
>
33
37
34
-
35
-
36
38
## Prerequisites
37
39
38
-
To complete this tutorial:
39
-
40
40
+[Create an Azure API Management instance](get-started-create-service-instance.md)
41
41
+[Import and publish an API](import-and-publish.md)
42
42
43
-
## Add the caching policies
43
+
## Add caching policies
44
44
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.
45
+
With the 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 return the cached response until the cache duration interval expires.
46
46
47
47
1. Sign in to the [Azure portal](https://portal.azure.com).
48
48
1. Browse to your API Management instance.
49
-
1. Select **APIs** > **APIs**from the menu on the left.
49
+
1. Select **APIs** > **APIs**in the menu on the left.
50
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.":::
51
+
1. At the top of the screen, select the **Design** tab.
52
+
1. In the **Inbound processing** section, select the **</>** icon:
53
+
54
+
:::image type="content" source="media/api-management-howto-cache/code-editor.png" alt-text="Screenshot that shows API Management APIs in the portal." lightbox="media/api-management-howto-cache/code-editor.png":::
54
55
55
-
8. In the `inbound` element, add the following policy:
56
+
1. In the `inbound` element, add the following policy:
@@ -62,33 +63,35 @@ With caching policies shown in this example, the first request to a test operati
62
63
</cache-lookup>
63
64
```
64
65
65
-
9. In the `outbound` element, add the following policy:
66
+
1. In the `outbound` element, add the following policy:
66
67
67
68
```xml
68
69
<cache-storeduration="20" />
69
70
```
70
71
71
-
In this policy, **duration** specifies the expiration interval of the cached responses. In this example, the interval is **20** seconds.
72
+
In this policy, `duration` specifies the expiration interval of the cached responses. The interval is 20 seconds.
72
73
73
74
> [!TIP]
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.
75
+
> If you're 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 might want to specify the `caching-type` attribute of the caching policies. See [API Management caching policies](api-management-policies.md#caching) for more information.
75
76
76
77
## Call an operation and test the caching
77
-
To see the caching in action, call an operation from the portal.
78
78
79
-
1. In the Azure portal, browse to your API Management instance.
80
-
1. Select **APIs** > **APIs** from the menu on the left.
79
+
To test caching, call an operation in the portal.
80
+
81
+
1. In the Azure portal, go to your API Management instance.
82
+
1. Select **APIs** > **APIs** in the menu on the left.
81
83
1. Select the API to which you added caching policies.
82
84
1. Select an operation to test.
83
-
1. Select the **Test** tab in the top right menu.
85
+
1. Select the **Test** tab at the top of the window.
84
86
1. Select **Trace** two or three times in quick succession.
85
87
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:
88
+
1.Go to the **Inbound** section and scroll to the `cache-lookup` policy. You should see a message similar to the one in the following screenshot, which indicates a cache hit:
87
89
:::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.":::
88
90
89
91
## Related content
92
+
90
93
* For more information about caching policies, see [Caching policies][Caching policies] in the [API Management policy reference][API Management policy reference].
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).
94
+
* For information on caching items by key by using policy expressions, see [Custom caching in Azure API Management](api-management-sample-cache-by-key.md).
92
95
* For more information about using external Azure Cache for Redis or Azure Managed Redis, see [Use an external Azure Cache for Redis in Azure API Management](api-management-howto-cache-external.md).
0 commit comments