This documentation is archived and is not being maintained.

Local Cache for Azure Managed Cache Service

Updated: August 25, 2015

Microsoft recommends all new developments use Azure Redis Cache. For current documentation and guidance on choosing an Azure Cache offering, see Which Azure Cache offering is right for me?

Local cache is a feature of Microsoft Azure Cache that improves performance by reducing network requests to the cache service. caching stores objects in serialized form in a distributed in-memory cache. When an application requests an object from the cache, the serialized object is sent to the requesting application over the network. The application then deserializes the object for its use. To speed up the process of retrieving an object, enable local cache.

When local cache is enabled, the cache client stores a reference to the object locally. This local reference keeps the object active in the memory of the client application. When the application requests the object, the cache client checks whether the object resides in the local cache. If so, the reference to the object is returned immediately without contacting the cache service. If it does not exist, the object is retrieved from the cache service. The cache client then deserializes the object and stores the reference to this newly retrieved object in the local cache. The client application uses this same object.

The lifetime of an object in the local cache depends on the maximum number of objects in the local cache and the invalidation policy. There are two types of invalidation for local cache: time-out-based invalidation and notification-based invalidation. For more information, see Expiration and Eviction for Azure Managed Cache Service.

Local cache can be enabled and configured using the web.config or application configuration file. You can add a localCache element to the dataCacheClient section. The following table lists the attributes of the localCache element.


Attribute Description


Set to true or false to enable or disable local cache.


Determines how the local cache is invalidated. Possible values are TimeoutBased and NotificationBased.


The maximum number of objects to store in the local cache. The default is 10000.


The number of seconds that objects stay in the local cache. The default is 300 seconds.

A sync value of TimeoutBased keeps objects cached locally until the ttlValue limit is reached. A value of NotificationBased uses notifications in addition to the timeout-based mechanism. To use notifications for invalidation, notifications must first be enabled for the cache by following the steps in Enabling Cache Notifications. The polling interval for notifications checks to see if items in the local cache have changed. An effective polling interval for notifications must be shorter than the ttlValue setting to be effective. An addition element, clientNotification, can be used to configure the poll interval for notifications by setting the pollInterval attribute to the number of second. The default is 300 seconds.

Notifications are available in the Standard and Premium cache offerings, and are not available in the Basic cache offering. For more information, see Cache Offerings for Azure Managed Cache Service.

The following example shows a dataCacheClient section that uses local cache with timeout-based local expiration of five minutes (300 seconds).

<dataCacheClient name="default">
  <!-- Other configuration settings for cache omitted -->
  <localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />

The following example shows the previous dataCacheClient section changed to use notifications to provide additional synchronization by polling every one minute (60 seconds).

<dataCacheClient name="default">
  <!-- Other configuration settings for cache omitted -->
  <localCache isEnabled="true" sync="NotificationBased" objectCount="100000" ttlValue="300" />
  <clientNotification pollInterval="60" />

To download a sample that uses local cache, see the Cache API and Performance Sample.

See Also