Use an external Azure Cache for Redis in Azure API Management

In addition to utilizing the built-in cache, Azure API Management also allows for caching responses in an external Azure Cache for Redis.

Using an external cache allows to overcome a few limitations of the built-in cache. It is especially beneficial if you would like to:

  • Avoid having your cache periodically cleared during API Management updates
  • Have more control over your cache configuration
  • Cache more data than your API Management tier allows to
  • Use caching with the Consumption tier of API Management

For more detailed information about caching, see API Management caching policies and Custom caching in Azure API Management.

Bring your own cache to APIM

What you'll learn:

  • Add an external cache in API Management

Prerequisites

To complete this tutorial, you need to:

Create Azure Cache for Redis

This section explains how to create an Azure Cache for Redis in Azure. If you already have an Azure Cache for Redis, within or outside of Azure, you can skip to the next section.

  1. To create a cache, first sign in to the Azure portal. Then select Create a resource > Databases > Azure Cache for Redis.

    New cache

  2. In New Azure Cache for Redis, configure the settings for your new cache.

    Setting Suggested value Description
    DNS name Globally unique name The cache name. It must be a string between 1 and 63 characters and contain only numbers, letters, and the - character. The cache name cannot start or end with the - character, and consecutive - characters are not valid.
    Subscription Your subscription The subscription under which this new Azure Cache for Redis instance is created.
    Resource group TestResources Name for the new resource group in which to create your cache. By putting all the resources for an app in a group, you can manage them together. For example, deleting the resource group deletes all resources that are associated with the app.
    Location East US Choose a region near to other services that will use your cache.
    Pricing tier Basic C0 (250 MB Cache) The pricing tier determines the size, performance, and features that are available for the cache. For more information, see Azure Cache for Redis Overview.
    Pin to dashboard Selected Pin the new cache to your dashboard to make it easy to find.

    Create cache

  3. After the new cache settings are configured, select Create.

    It can take a few minutes for the cache to be created. To check the status, you can monitor the progress on the dashboard. After the cache has been created, it shows the status Running, and is ready for use.

    Cache created

Add an external cache

Follow the steps below to add an external Azure Cache for Redis in Azure API Management.

Bring your own cache to APIM

Note

The Use from setting specifies which API Management regional deployment will communicate with the configured cache in case of a multi-regional configuration of API Management. The caches specified as Default will be overridden by caches with a regional value.

For example, if API Management is hosted in the East US, Southeast Asia and West Europe regions and there are two caches configured, one for Default and one for Southeast Asia, API Management in Southeast Asia will use its own cache, while the other two regions will use the Default cache entry.

Add an Azure Cache for Redis from the same subscription

  1. Browse to your API Management instance in the Azure portal.
  2. Select the External cache tab from the menu on the left.
  3. Click the + Add button.
  4. Select your cache in the Cache instance dropdown field.
  5. Select Default or specify the desired region in the Use from dropdown field.
  6. Click Save.

Add an Azure Cache for Redis hosted outside of the current Azure subscription or Azure in general

  1. Browse to your API Management instance in the Azure portal.
  2. Select the External cache tab from the menu on the left.
  3. Click the + Add button.
  4. Select Custom in the Cache instance dropdown field.
  5. Select Default or specify the desired region in the Use from dropdown field.
  6. Provide your Azure Cache for Redis connection string in the Connection string field.
  7. Click Save.

Use the external cache

Once the external cache is configured in Azure API Management, it can be used through caching policies. See Add caching to improve performance in Azure API Management for detailed steps.

Next steps