FX::FXLRUCache< dictbase, type > Class Template Reference
#include <FXLRUCache.h>
Inheritance diagram for FX::FXLRUCache< dictbase, type >:
List of all members.
Detailed Description
template<class dictbase, class type>
class FX::FXLRUCache< dictbase, type >
A generic Least Recently Used (LRU) Cache (Qt compatible).
To maximise performance in modern systems which tend to have plenty of free RAM, caching can be used to speed up cases where possibly the same processing may need to be repeated. When I wrote this class, I had the Tornado kernel namespace nodes in mind, but it's generically applicable to any similar situation.
Some effort is made to replicate the Qt API for QCache, sufficiently that with suitable typedef
-ing of the template parameters you can make a compatible QCache or QIntCache. However anything that FX::QDictBase can be configured with can also make a FXLRUCache.
One interesting feature of FXLRUCache is that it can handle value objects. This was done primarily with FX::FXRefingObject in mind but its use exists outside of that. To enable FXLRUCache as a value-based container, use the following form:
typedef FXLRUCache<QDict<Foo>, Foo> FooValueCache;
Leaving out the second template parameter causes FXLRUCache to use the dictionary's type which of course is always a pointer. If value-based semantics are enabled, auto-deletion becomes always enabled.
If dynamic mode is enabled, maxCost() is shifted right by FXProcess::memoryFull(). By default dynamic mode is enabled.
Definition at line 79 of file FXLRUCache.h.
|
Public Types |
typedef dictbase::KeyType | KeyType |
typedef dictbase::ItemType | FundamentalDictType |
Public Member Functions |
| FXLRUCache (FXuint maxCost=100, FXuint size=13, bool autodel=false) |
void | setAutoDelete (bool a) |
bool | dynamic () const throw () |
void | setDynamic (bool v) const throw () |
FXuint | maxCost () const throw () |
void | setMaxCost (FXuint newmax) |
FXuint | totalCost () const throw () |
void | cacheStats (float *hitrate, float *churn) const throw () |
void | statistics () const |
bool | insert (KeyTypeAsParam k, TypeAsParam d, FXint itemcost=1) |
bool | remove (KeyTypeAsParam k) |
TypeAsReturn | take (KeyTypeAsParam k) |
TypeAsReturn | find (KeyTypeAsParam k, bool tofront=true) const |
TypeAsReturn | operator[] (KeyTypeAsParam k) const |
Protected Types |
typedef FundamentalDictType * | DictType |
typedef Generic::select< Generic::sameType<
type, Generic::NullType
>::value, DictType, type
>::value | Type |
typedef Generic::TraitsBasic<
Type > | TypeTraits |
typedef Generic::TraitsBasic<
KeyType >::asROParam | KeyTypeAsParam |
typedef TypeTraits::asROParam | TypeAsParam |
typedef Generic::leastIndir<
Type >::value * | TypeAsReturn |
typedef FXLRUCacheImpl::getPtr<
Type, TypeAsParam, TypeTraits::isValue > | CacheItemBase |
Protected Member Functions |
virtual void | purgeLFU () |
virtual void | deleteItem (DictType d) |
Protected Attributes |
FXuint | topmax |
FXuint | maximum |
FXuint | cost |
bool | amDynamic |
std::list< CacheItem > | cache |
FX::FXLRUCache::stats_t | stats |
Friends |
class | FXLRUCacheIterator |
Classes |
struct | CacheItem |
struct | stats_t |
The documentation for this class was generated from the following file:
(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:34:43 2009 for TnFOX by
v1.4.7