Export (0) Print
Expand All

Local Cache (In-Role Cache for Azure Cache)

Updated: July 17, 2010

noteNote
For guidance on choosing the right Azure Cache offering for your application, 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.

Local Cache Overview

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-Role Cache for Azure Cache).

Configuration Settings

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

isEnabled

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

sync

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

objectCount

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

ttlValue

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.

noteNote
Notifications are an In-Role Cache feature supported only in caches that are hosted on roles. Notifications are not supported in Microsoft Azure Shared Caching.

Examples

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" />
    </dataCacheClient>

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" />
    </dataCacheClient>

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

See Also

Community Additions

ADD
Show:
© 2014 Microsoft