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.
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] |
enum OSB_LIB::PersProductCache::GuardStatus [private] |
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.
Entry* OSB_LIB::PersProductCache::add | ( | Key & | key, | |
const PersProduct & | persProduct | |||
) | [private] |
Add a resource and pers. product to the cache.
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.
ReadGuard<PersProduct*> OSB_LIB::PersProductCache::find | ( | const OSB_DB::Session & | session, | |
const ResourceKey & | resourceKey, | |||
const DateTime & | timestamp | |||
) |
Find the personalized product of a resource.
session | Database session to use. | |
resourceKey | Resource to find. | |
timestamp | Date and time for which to find the pers. product. |
OsbException | if pers. product can not be read from the database. | |
OsbException | in case of an internal error. |
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.
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] |
Mutex OSB_LIB::PersProductCache::mutex_ [private] |
long OSB_LIB::PersProductCache::nextMiss_ [private] |
Queue OSB_LIB::PersProductCache::queue_ [private] |
Keys OSB_LIB::PersProductCache::resources_ [private] |
Stats OSB_LIB::PersProductCache::stats_ [private] |
bool OSB_LIB::PersProductCache::useLocks_ [private] |