LRUCache Object [C++]

Use this object to support the creation, storage, and retrieval of name/value pairs, referred to as elements, from a cache in memory. The LRUCache object functions similarly to the Dictionary object, except that it only stores a limited number of elements, and internally ranks them according to use. When the cache is full and a new element needs to be added, the least recently used element is removed from the cache to make room for the new element.

ProgID:   Commerce.LRUCache (Externally creatable)
COM Class Name:   LRUCache
Type Library Name:   Microsoft Commerce 2002 Cache Manager Type Library
DLL Name:   mscscache.dll
Threading Model:   Both

[C++]

COM Interface Name:   ILRUCache
Interface ID Constant:   IID_ILRUCache
Header File:   cacheint.h, mspu_guids.h

[C++]

In C++, use the ILRUCache interface to access the methods of the LRUCache object.

Because this object is primarily intended for use within ASP script, access from C++ will not be common.

Methods

[C++]

Method Description
Flush Removes an element from the cache.
FlushAll Removes all elements from the cache.
Insert Inserts an element into the cache.
Lookup Returns the value of an element in the cache when given the name of the element.
LookupObject Returns an object in the cache when given the name of the object.
SetSize Sets the maximum size of the cache.

[Visual Basic]

Method Description
Flush Removes an element from the cache.
FlushAll Removes all elements from the cache.
Insert Inserts an element into the cache.
Lookup Returns the value of an element in the cache when given the name of the element.
LookupObject Returns an object in the cache when given the name of the object.
SetSize Sets the maximum size of the cache.

Remarks

The LRUCache object is typically created by the CacheManager object rather than directly from an ASP script. It is configured through the Cachemanager.LoaderConfig property. This is done by configuring a CacheManager cache with a LoaderProgID of Commerce.LRUCacheFlush and by setting the LoaderConfig dictionary properties as shown in the table below. The configuration parameters are contained in a Dictionary object.

The following table shows the keys in the dictionary containing the configuration parameters.

Key Definition
CacheSize Specifies the size of the cache. A value of –1 will result in the default value of 1000 items being used.
ConnectionString The connection string to the database where the LRUCacheFlush object should register the cache.
TableName The name of the table where the LRUCacheFlush object should register the cache.
AppUrl The fully qualified URL of the Commerce Server application without a page name.
CacheName The name of the cache.

Ee797730.note(en-US,CS.20).gifNote

  • The ConnecitonString, TableName, and CacheName keys are required. If any of them are not set the LRUCacheFlush object will not register the cache.

The LRUCacheFlush object registers the LRUCache object so that it can be flushed from Commerce Server Business Desk.

The default maximum size of the cache is 1000 items but you can set the size to whatever you need by using the SetSize() method.

The cache is designed so that once the number of items in the cache reaches 110% of the maximum size, the 10% least recently used items are flushed.

The algorithm uses an approximate LRU so there is no guarantee that a particular item will or will not be flushed. The cache is agnostic to memory pressure: it only cares about the number of items.

The cache operates by storing data of type VARIANT so you can cache anything that can be stored in a VARIANT.

Ee797730.note(en-US,CS.20).gifNote

  • It is possible to store pointers in the cache, and then delete the underlying objects, which would cause the data to become corrupt. This should not be an issue if you are storing strings.

For additional information about LRUCache, see “Refreshing Commerce Server Caches” at https://go.microsoft.com/fwlink/?LinkId=15097.

To view a sample configuration of the LRUCache object, see Code to Use Caching with a Catalog.

See Also

[C++]CacheManager Object

[Visual Basic]CacheManager Object

Code to Use Caching with a Catalog

Code to Manipulate an LRUCache Object

Copyright © 2005 Microsoft Corporation.
All rights reserved.