Store value in cache
cache-store-value performs cache storage by key. The key can have an arbitrary string value and is typically provided using a policy expression.
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.
Built-in cache is volatile and is shared by all units in the same region in the same API Management service.
Set the policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.
<cache-store-value key="cache key value" value="value to cache" duration="seconds" caching-type="prefer-external | external | internal" />
|caching-type||Choose between the following values of the attribute:
Policy expressions aren't allowed.
|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|
- Policy sections: inbound, outbound, backend, on-error
- Policy scopes: global, workspace, product, API, operation
- Gateways: dedicated, consumption, self-hosted
<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.
For more information about working with policies, see: