This documentation is archived and is not being maintained.

Local Cache in Azure In-Role Cache

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 remote caches. Microsoft Azure Cache stores objects in serialized form in an in-memory cache that is distributed over multiple servers. When an application requests an object from the cache, the server that stores that object is identified. That server then sends the serialized object 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 server. If it does not exist, the object is retrieved from the server. 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 in Azure In-Role Cache.

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, enable notifications for the cache. 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 an In-Role Cache feature supported only in caches that are hosted on Azure roles.

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 -->
      <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). Notifications are only supported with role-based In-Role Cache.

    <dataCacheClient name="default">
      <autoDiscover isEnabled="true" identifier="WebRole1" />
      <localCache isEnabled="true" sync="NotificationBased" objectCount="100000" ttlValue="300" />
      <clientNotification pollInterval="60" />

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

See Also