Skip to content

Latest commit

 

History

History
73 lines (48 loc) · 4.66 KB

File metadata and controls

73 lines (48 loc) · 4.66 KB
title Azure API Management policy reference - cache-store-value | Microsoft Docs
description Reference for the cache-store-value policy available for use in Azure API Management. Provides policy usage, settings, and examples.
services api-management
author dlepow
ms.service azure-api-management
ms.topic reference
ms.date 07/23/2024
ms.author danlep

Store value in cache

[!INCLUDE api-management-availability-all-tiers]

The cache-store-value performs cache storage by key. The key can have an arbitrary string value and is typically provided using a policy expression.

Note

The operation of storing the value in cache performed by this policy is asynchronous. The stored value can be retrieved using Get value from cache policy. However, the stored value may not be immediately available for retrieval since the asynchronous operation that stores the value in cache may still be in progress.

[!INCLUDE api-management-cache-volatile]

[!INCLUDE api-management-policy-generic-alert]

Policy statement

<cache-store-value key="cache key value" value="value to cache" duration="seconds" caching-type="prefer-external | external | internal" />

Attributes

Attribute Description Required Default
caching-type Choose between the following values of the attribute:
- internal to use the built-in API Management cache,
- external to use the external cache as described in Use an external Redis-compatible cache in Azure API Management,
- prefer-external to use external cache if configured or internal cache otherwise.

Policy expressions aren't allowed.
No prefer-external
duration Value will be cached for the provided duration value, specified in seconds. Policy expressions are allowed. Yes N/A
key Cache key the value will be stored under. Policy expressions are allowed. Yes N/A
value The value to be cached. Policy expressions are allowed. Yes N/A

Usage

Usage notes

  • API Management only caches responses to HTTP GET requests.
  • This policy can only be used once in a policy section.
  • [!INCLUDE api-management-cache-rate-limit]

Example

This example shows how to use the cache-store-value policy to store a user profile in the cache. The key for the cache entry is constructed using a policy expression that combines a string with the value of the enduserid context variable.

See a cache-lookup-value example to retrieve the user profile from the cache.

<cache-store-value
    key="@("userprofile-" + context.Variables["enduserid"])"
    value="@((string)context.Variables["userprofile"])" duration="100000" />

For more information and examples of this policy, see Custom caching in Azure API Management.

Related policies

[!INCLUDE api-management-policy-ref-next-steps]