OSB_LIB::PersProductCache Class Reference

Collaboration diagram for OSB_LIB::PersProductCache:

Collaboration graph
[legend]
List of all members.

Detailed Description

Cache for personalised products.

This class stores the assignment of resources to personalised products in memory.
The validity of a cached entry is verified after cacheTime_ seconds have elapsed since the entry was read from the database. The flag useLocks_ determines if the cache is used in a multi-thread application and must locks its data structures.

Internally the cache uses 3 STL containers:
PersProductCache::Keys stored the assignment of resources to pers. products. For one pers. product multiple keys can exist.

PersProductCache::Queue keeps the most recently used (MRU) pers. products at its begin.
If the cache size is exceeded, the least recently used entries are evicted.

PersProductCache::PersProducts stored the pers. personalized products.
For efficient cache maintenance, an entry stores the links to its keys and its position in the MRU queue.

Definition at line 77 of file persproductcache.h.

Public Member Functions

Private Types

Private Member Functions

Private Attributes

Classes


Member Typedef Documentation

typedef std::map<Key, PersProduct::Oid> OSB_LIB::PersProductCache::Keys [private]

Map of resources to pers. products.

The container links the resource key and assignment period to the pers. product who owned the resource during this time.

Definition at line 213 of file persproductcache.h.

typedef std::map<PersProduct::Oid, Entry*> OSB_LIB::PersProductCache::PersProducts [private]

Container of personalised product and it's related information.

This is the most important container. For a pers. product id (key), it keeps a pointer to the pers. product and other info. If an entry is added or deleted to/from this container, the other two containers are updated as well.

Definition at line 129 of file persproductcache.h.

typedef std::list<PersProduct::Oid> OSB_LIB::PersProductCache::Queue [private]

MRU queue of pers. product ids.

Definition at line 218 of file persproductcache.h.


Member Enumeration Documentation

enum OSB_LIB::PersProductCache::GuardStatus [private]

Status of the pers. product guard.

Enumerator:
ppFound  Pers. product found.
ppNotFound  Pers. product not found.

Definition at line 142 of file persproductcache.h.


Constructor & Destructor Documentation

OSB_LIB::PersProductCache::PersProductCache ( bool  useLocks  )  [explicit]

Constructor with maximum chache size.

OSB_LIB::PersProductCache::~PersProductCache (  ) 

Default d'tor.

OSB_LIB::PersProductCache::PersProductCache ( const PersProductCache  )  [private]

Prevent copying: not implemented.


Member Function Documentation

Entry* OSB_LIB::PersProductCache::add ( Key key,
const PersProduct persProduct 
) [private]

Add a resource and pers. product to the cache.

void OSB_LIB::PersProductCache::addKey ( Entry entry,
Key key 
) [private]

Add a resource for a pers. product.

Entry* OSB_LIB::PersProductCache::addMiss ( const OSB_DB::Session session,
Key key,
const DateTime timestamp 
) [private]

Add an entry for which no assignment exits.

void OSB_LIB::PersProductCache::adjustSize (  )  [private]

Adjust the cache size.

Entry* OSB_LIB::PersProductCache::find ( const Key key  )  [private]

Get an existing entry.

ReadGuard<PersProduct*> OSB_LIB::PersProductCache::find ( const OSB_DB::Session session,
const ResourceKey resourceKey,
const DateTime timestamp 
)

Find the personalized product of a resource.

Parameters:
session Database session to use.
resourceKey Resource to find.
timestamp Date and time for which to find the pers. product.
Exceptions:
OsbException if pers. product can not be read from the database.
OsbException in case of an internal error.
Returns:
A read guard to the pers. product that owns resourceKey at timestamp.
If no matching pers. product exists in the database, its pointer is 0 and the status is ppNotFound.
Note:
This is the only function that locks the whole cache.

Entry* OSB_LIB::PersProductCache::load ( const OSB_DB::Session session,
Key key,
const DateTime timestamp,
bool  isReload 
) [private]

Load data for a key from the database.

void OSB_LIB::PersProductCache::logStats (  )  const

Print cache statistics to Log.

PersProductCache& OSB_LIB::PersProductCache::operator= ( PersProductCache  )  [private]

Prevent assignment: not implemented.

void OSB_LIB::PersProductCache::remove ( const PersProduct::Oid ppId,
bool  force 
) [private]

Remove a pers. product from the cache.

void OSB_LIB::PersProductCache::setCacheTime ( long  cacheTime  ) 

Set the cache time in seconds.

This is the time used to decide if the status of a cache entry must be verified against the database and refreshed if needed.

void OSB_LIB::PersProductCache::setMaxSize ( long  maxSize  ) 

Set the maximum cache size.


Member Data Documentation

long OSB_LIB::PersProductCache::cacheTime_ [private]

Number of seconds a cached pers. product is considered valid.

Definition at line 278 of file persproductcache.h.

unsigned long OSB_LIB::PersProductCache::maxSize_ [private]

Maximum size of the cache.

Definition at line 273 of file persproductcache.h.

Mutex OSB_LIB::PersProductCache::mutex_ [private]

Mutex to protect the cache.

Definition at line 284 of file persproductcache.h.

long OSB_LIB::PersProductCache::nextMiss_ [private]

Next id to use for non-existing assignments.

Definition at line 281 of file persproductcache.h.

PersProducts OSB_LIB::PersProductCache::persProducts_ [private]

Pers. product and related information by id.

Definition at line 264 of file persproductcache.h.

Queue OSB_LIB::PersProductCache::queue_ [private]

Queue with MRU pers. products at the begin.

Definition at line 268 of file persproductcache.h.

Keys OSB_LIB::PersProductCache::resources_ [private]

Resource key and time to pers product id.

Definition at line 266 of file persproductcache.h.

Stats OSB_LIB::PersProductCache::stats_ [private]

Cache statistics.

Definition at line 289 of file persproductcache.h.

MutexUnlock OSB_LIB::PersProductCache::unlock_ [private]

Object to unlock the cache.

Definition at line 286 of file persproductcache.h.

bool OSB_LIB::PersProductCache::useLocks_ [private]

Flag to use locks or not.

Definition at line 271 of file persproductcache.h.


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:12:33 2006 for OSB Library by  doxygen 1.4.7