Skip to main content
ATL Server Library Reference 
CMemoryCacheBase Class 

This class provides features for caching generic items in memory.


template <
   class T,
   class DataType,
   class NodeInfo  = CCacheDataBase,
   class keyType   = CFixedStringKey,
   class KeyTrait  = CStringElementTraits< CFixedStringKey >,
   class Flusher   = COldFlusher,
   class Culler    = CExpireCuller,
   class SyncClass = CComCriticalSection,
   class StatClass = CStdStatClass
>
class CMemoryCacheBase

Parameters

T

A class derived from CMemoryCacheBase<T, ...>. This class must implement a method with this signature:

void OnDestroyEntry(NodeType* pEntry);

The implementation of this method should free any custom data allocated for the cache entry and perform other custom cleanup when an item is removed from the cache. See CMemoryCacheBase::NodeType Structure.

DataType

The data structure that defines the data to be cached. This structure holds the data that users of the cache must provide when adding items to the cache.

NodeInfo

The data structure that provides auxiliary information about each cached item. This structure is used by derived classes to hold data that is used in the implementation of the cache and is not intended for direct manipulation by users of the cache. See CMemoryCacheBase::NodeType Structure.

keyType

The type used to identify elements in the cache.

KeyTrait

The type used to compare keyType objects.

Flusher

The class used to determine whether, and in what order, items should be removed from the cache using the number and sequence of accesses as the basis for making the decision. Must conform to the cache flusher archetype.

CMemoryCacheBase asks a data member of this type to provide candidates for removal when FlushEntries is called and the number of entries in the cache or the size of the cache exceeds the limit set by a previous call to SetMaxAllowedEntries or SetMaxAllowedSize.

Culler

The class used to determine to determine whether, and in what order, items should be removed from the cache using time-based criteria. Must conform to the cache culler archetype.

CMemoryCacheBase asks a data member of this type to provide candidates for removal when either CullEntries or FlushEntries is called.

SyncClass

The name of the class to be used for thread synchronization. The default value of CComCriticalSection is suitable for most situations, but CComFakeCriticalSection can be used to avoid thread synchronization in single-threaded environments.

StatClass

The class used to collect and expose statistics related to the use of the cache including such information as effectiveness of the cache and memory used. Must conform to the cache statistics archetype.

This class provides the implementation of a generic cache that stores elements in memory. The ATL Server cache implementations CMemoryCache, CBlobCache, CFileCache, and CStencilCache classes all use CMemoryCacheBase as a base class.

The items in the cache are reference counted to ensure that multiple clients can access the same items without ill effects. See AddRefEntry and RemoveEntry for more details.

The keyType and keyTrait template arguments define the data type that the cache uses to access entries. By default, CFixedStringKey is used, providing cache keys that use ANSI string of a fixed length defined by ATL_CACHE_KEY_LENGTH. Cache entries must have unique key values. If you try to add an entry with a key that is exactly the same as an existing key, the existing entry will be overwritten.

Header: atlcache.h