Caching Programming Concepts

There are two cache objects used by Commerce Server 2002, the CacheManager object and the LRUCache object. This section provides an overview of the programming concepts associated with these objects.

This section contains:

  • CacheManager Object
  • LRUCache Object

CacheManager Object

The CacheManager object is normally created in the Application_OnStart event in the Global.asa file for an Active Server Pages (ASP) application. It uses the services of other Component Object Model (COM) objects called Loader and Writer components, whose job it is to populate caches with data and write data that has been collected in the cache, respectively. Each cache is required to have a Loader component configured, but the Writer component is optional. The CacheManager object is configured by setting the LoaderProgId, LoaderConfig, WriterProgId, and WriterConfig properties for each cache being created.

After one or more caches have been configured in an application, any ASP page in the application can use the GetCache method of the CacheManager object to access the cached data. The type of cache object returned, either a Dictionary object or an LRUCache object, depends on the configuration of the LoaderProgId property for the cache.

The CacheManager object can be configured to automatically refresh each cache periodically, based on the RefreshInterval property. Automatic cache refresh can also be disabled by setting the RefreshInterval property to zero (0), which is the default. The CacheManager object also retries failed load operations after a configurable pause, controlled with the RetryInterval property.

When the CacheManager object refreshes the cache, either from an explicit call to the RefreshCache method or based on the refresh interval expiring, it performs several actions. First, if the cache has been configured with a Writer component, the CacheManager object creates, configures, and executes the Writer component to record performance data collected since the last refresh operation. If the Writer component fails, then the entire refresh operation is aborted. Next, the CacheManager object creates, configures, and executes the specified Loader component to repopulate the cache. A Loader component can be designed such that if it determines that the existing contents of the cache are current, or otherwise sufficient, it can simply return a CACHE_E_NOCACHE_UPDATED message. When the CacheManager object recognizes this return code, it does not replace the existing cache with the newly created one that was passed to the Loader component, and any changes that were made to the new cache object are discarded.

For more information, see CacheManager Object.

LRUCache Object

The LRUCache object is used to support the creation, storage, and retrieval of key/value pairs from a cache. LRUCache objects are similar to Dictionary objects, except that LRUCache objects can only store a limited number of elements. The LRUCache object ranks elements from most-recently-used to least-recently-used. When the LRUCache object is at capacity, it removes the least-recently-used element from the cache and adds the new element. The replacement algorithm used by the LRUCache object is an approximate method that allows the cache size to grow to 110 percent of its maximum size setting. After this limit is reached, the least-recently-used 10 percent of items are removed from the cache.

For more information, see LRUCache Object.

Copyright © 2005 Microsoft Corporation.
All rights reserved.