Template cache with an LRU removal policy.
More...
#include <lru_cache.h>
|
typedef std::list< std::pair
< Key, Data > > | List |
| Main cache storage typedef.
|
|
typedef List::iterator | List_Iter |
| Main cache iterator.
|
|
typedef List::const_iterator | List_cIter |
| Main cache iterator (const)
|
|
typedef std::vector< Key > | Key_List |
| List of keys.
|
|
typedef Key_List::iterator | Key_List_Iter |
| Main cache iterator.
|
|
typedef Key_List::const_iterator | Key_List_cIter |
| Main cache iterator (const)
|
|
typedef std::map< Key, List_Iter > | Map |
| Index typedef.
|
|
typedef std::pair< Key, List_Iter > | Pair |
| Pair of Map elements.
|
|
typedef Map::iterator | Map_Iter |
| Index iterator.
|
|
typedef Map::const_iterator | Map_cIter |
| Index iterator (const)
|
|
|
| LRUCache (const unsigned long Size) |
| Creates a cache that holds at most Size worth of elements. More...
|
|
| LRUCache (const LRUCache &that) |
|
LRUCache & | operator= (const LRUCache &that) |
|
| ~LRUCache () |
| Destructor - cleans up both index and storage.
|
|
unsigned long | size (void) const |
| Gets the current abstract size of the cache. More...
|
|
unsigned long | max_size (void) const |
| Gets the maximum sbstract size of the cache. More...
|
|
void | clear (void) |
| Clears all storage and indices.
|
|
bool | exists (const Key &key) const |
| Checks for the existance of a key in the cache. More...
|
|
void | remove (const Key &key) |
| Removes a key-data pair from the cache. More...
|
|
void | touch (const Key &key) |
| Touches a key in the Cache and makes it the most recently used. More...
|
|
Data * | fetch_ptr (const Key &key, bool touch_data=true) |
| Fetches a pointer to cache data. More...
|
|
Data | fetch (const Key &key, bool touch_data=true) |
| Fetches a copy of cached data. More...
|
|
bool | fetch (const Key &key, Data &data, bool touch_data=true) |
| Fetches a pointer to cache data. More...
|
|
void | insert (const Key &key, const Data &data) |
| Inserts a key-data pair into the cache and removes entries if neccessary. More...
|
|
void | info () |
|
const Key_List | get_all_keys (void) |
| Get a list of keys. More...
|
|
template<class Key, class Data, class Sizefn = Countfn< Data >>
class LRUCache< Key, Data, Sizefn >
Template cache with an LRU removal policy.
- This template creats a simple collection of key-value pairs that grows until the size specified at construction is reached and then begins discard the Least Recently Used element on each insertion.
template<class Key, class Data, class Sizefn = Countfn< Data >>
Creates a cache that holds at most Size worth of elements.
- Parameters
-
Size | maximum size of cache |
template<class Key, class Data, class Sizefn = Countfn< Data >>
bool LRUCache< Key, Data, Sizefn >::exists |
( |
const Key & |
key | ) |
const |
|
inline |
Checks for the existance of a key in the cache.
- Parameters
-
- Returns
- bool indicating whether or not the key was found.
template<class Key, class Data, class Sizefn = Countfn< Data >>
Data LRUCache< Key, Data, Sizefn >::fetch |
( |
const Key & |
key, |
|
|
bool |
touch_data = true |
|
) |
| |
|
inline |
Fetches a copy of cached data.
- Parameters
-
key | to fetch data for |
touch_data | whether or not to touch the data |
- Returns
- copy of the data or an empty Data object if not found
template<class Key, class Data, class Sizefn = Countfn< Data >>
bool LRUCache< Key, Data, Sizefn >::fetch |
( |
const Key & |
key, |
|
|
Data & |
data, |
|
|
bool |
touch_data = true |
|
) |
| |
|
inline |
Fetches a pointer to cache data.
- Parameters
-
key | to fetch data for |
data | to fetch data into |
touch_data | whether or not to touch the data |
- Returns
- whether or not data was filled in
template<class Key, class Data, class Sizefn = Countfn< Data >>
Data* LRUCache< Key, Data, Sizefn >::fetch_ptr |
( |
const Key & |
key, |
|
|
bool |
touch_data = true |
|
) |
| |
|
inline |
Fetches a pointer to cache data.
- Parameters
-
key | to fetch data for |
touch | whether or not to touch the data |
- Returns
- pointer to data or NULL on error
template<class Key, class Data, class Sizefn = Countfn< Data >>
Get a list of keys.
- Returns
- list of the current keys.
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::insert |
( |
const Key & |
key, |
|
|
const Data & |
data |
|
) |
| |
|
inline |
Inserts a key-data pair into the cache and removes entries if neccessary.
- Parameters
-
key | object key for insertion |
data | object data for insertion |
- Note
- This function checks key existance and touches the key if it already exists.
template<class Key, class Data, class Sizefn = Countfn< Data >>
unsigned long LRUCache< Key, Data, Sizefn >::max_size |
( |
void |
| ) |
const |
|
inline |
Gets the maximum sbstract size of the cache.
- Returns
- maximum size
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::remove |
( |
const Key & |
key | ) |
|
|
inline |
Removes a key-data pair from the cache.
- Parameters
-
template<class Key, class Data, class Sizefn = Countfn< Data >>
unsigned long LRUCache< Key, Data, Sizefn >::size |
( |
void |
| ) |
const |
|
inline |
Gets the current abstract size of the cache.
- Returns
- current size
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::touch |
( |
const Key & |
key | ) |
|
|
inline |
Touches a key in the Cache and makes it the most recently used.
- Parameters
-
The documentation for this class was generated from the following file:
- /net/opt/univers/ubp-i-15.3-centos7-x64.urij/include/hds_db/qsql/lru_cache.h