Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::Cache< KEYTYPE, VALUETYPE > Class Template Reference

Cache is a generic caching storage class. More...

#include <Kernel/Cache.h>

Public Member Functions

 Cache ()
 No-arg Constructor. More...
 
 Cache (const Cache< KEYTYPE, VALUETYPE > &src)
 Copy constructor (mutex cannot be copied) More...
 
void clear ()
 Clears the cache. More...
 
bool getCache (const KEYTYPE &key, VALUETYPE &value) const
 Attempts to retrieve a value from the cache, with optional cache stats tracking. More...
 
int hitCount ()
 total number of times the cache has contained the requested information More...
 
double hitRatio ()
 total number of times the cache has contained the requested information/the total number of requests More...
 
int missCount ()
 total number of times the cache has contained the requested information More...
 
Cache< KEYTYPE, VALUETYPE > & operator= (const Cache< KEYTYPE, VALUETYPE > &rhs)
 Copy-assignment operator as we have a non-default copy constructor. More...
 
void removeCache (const KEYTYPE &key)
 Attempts to remove a value from the cache. More...
 
void setCache (const KEYTYPE &key, const VALUETYPE &value)
 Inserts/updates a cached value with the given key. More...
 
int size ()
 The number of cache entries. More...
 

Private Types

using CacheMapConstIterator = typename std::map< KEYTYPE, VALUETYPE >::const_iterator
 const_iterator typedef More...
 
using CacheMapIterator = typename std::map< KEYTYPE, VALUETYPE >::iterator
 iterator typedef More...
 

Private Member Functions

bool getCacheNoStats (const KEYTYPE key, VALUETYPE &value) const
 Attempts to retrieve a value from the cache. More...
 

Private Attributes

int m_cacheHit
 total number of times the cache has contained the requested information More...
 
std::map< KEYTYPE, VALUETYPE > m_cacheMap
 internal cache map More...
 
int m_cacheMiss
 total number of times the cache has not contained the requested information More...
 
std::mutex m_mutex
 internal mutex More...
 

Detailed Description

template<class KEYTYPE, class VALUETYPE>
class Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >

Cache is a generic caching storage class.

Author
Nick Draper, Tessella Support Services plc
Date
20/10/2009

Definition at line 27 of file Cache.h.

Member Typedef Documentation

◆ CacheMapConstIterator

template<class KEYTYPE , class VALUETYPE >
using Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::CacheMapConstIterator = typename std::map<KEYTYPE, VALUETYPE>::const_iterator
private

const_iterator typedef

Definition at line 156 of file Cache.h.

◆ CacheMapIterator

template<class KEYTYPE , class VALUETYPE >
using Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::CacheMapIterator = typename std::map<KEYTYPE, VALUETYPE>::iterator
private

iterator typedef

Definition at line 154 of file Cache.h.

Constructor & Destructor Documentation

◆ Cache() [1/2]

template<class KEYTYPE , class VALUETYPE >
Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::Cache ( )
inline

No-arg Constructor.

Definition at line 30 of file Cache.h.

◆ Cache() [2/2]

template<class KEYTYPE , class VALUETYPE >
Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::Cache ( const Cache< KEYTYPE, VALUETYPE > &  src)
inline

Copy constructor (mutex cannot be copied)

Parameters
srcThe object that this object shall be constructed from.

Definition at line 36 of file Cache.h.

Member Function Documentation

◆ clear()

template<class KEYTYPE , class VALUETYPE >
void Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::clear ( )
inline

Clears the cache.

Definition at line 56 of file Cache.h.

◆ getCache()

template<class KEYTYPE , class VALUETYPE >
bool Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::getCache ( const KEYTYPE &  key,
VALUETYPE &  value 
) const
inline

Attempts to retrieve a value from the cache, with optional cache stats tracking.

See also
USE_CACHE_STATS compiler define
Parameters
keyThe key for the requested value
valueAn output reference for the value, set to the curretn value if found, otherwise it is untouched
Returns
True if the value was found, false otherwise

Definition at line 98 of file Cache.h.

References PARALLEL_ATOMIC, and value.

◆ getCacheNoStats()

template<class KEYTYPE , class VALUETYPE >
bool Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::getCacheNoStats ( const KEYTYPE  key,
VALUETYPE &  value 
) const
inlineprivate

Attempts to retrieve a value from the cache.

Parameters
keyThe key for the requested value
valueAn output reference for the value, set to the curretn value if found, otherwise it is untouched
Returns
True if the value was found, false otherwise

Definition at line 132 of file Cache.h.

References value.

◆ hitCount()

template<class KEYTYPE , class VALUETYPE >
int Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::hitCount ( )
inline

total number of times the cache has contained the requested information

Definition at line 67 of file Cache.h.

◆ hitRatio()

template<class KEYTYPE , class VALUETYPE >
double Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::hitRatio ( )
inline

total number of times the cache has contained the requested information/the total number of requests

Definition at line 72 of file Cache.h.

◆ missCount()

template<class KEYTYPE , class VALUETYPE >
int Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::missCount ( )
inline

total number of times the cache has contained the requested information

Definition at line 69 of file Cache.h.

◆ operator=()

template<class KEYTYPE , class VALUETYPE >
Cache< KEYTYPE, VALUETYPE > & Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::operator= ( const Cache< KEYTYPE, VALUETYPE > &  rhs)
inline

Copy-assignment operator as we have a non-default copy constructor.

Parameters
rhsThe object that is on the RHS of the assignment

Definition at line 45 of file Cache.h.

References rhs.

◆ removeCache()

template<class KEYTYPE , class VALUETYPE >
void Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::removeCache ( const KEYTYPE &  key)
inline

Attempts to remove a value from the cache.

If the key does not exist, it does nothing

Parameters
keyThe key whose value should be removed

Definition at line 119 of file Cache.h.

◆ setCache()

template<class KEYTYPE , class VALUETYPE >
void Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::setCache ( const KEYTYPE &  key,
const VALUETYPE &  value 
)
inline

Inserts/updates a cached value with the given key.

Parameters
keyThe key
valueThe new value for the key

Definition at line 85 of file Cache.h.

References value.

◆ size()

template<class KEYTYPE , class VALUETYPE >
int Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::size ( )
inline

The number of cache entries.

Definition at line 64 of file Cache.h.

Member Data Documentation

◆ m_cacheHit

template<class KEYTYPE , class VALUETYPE >
int Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::m_cacheHit
mutableprivate

total number of times the cache has contained the requested information

Definition at line 145 of file Cache.h.

◆ m_cacheMap

template<class KEYTYPE , class VALUETYPE >
std::map<KEYTYPE, VALUETYPE> Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::m_cacheMap
private

internal cache map

Definition at line 150 of file Cache.h.

◆ m_cacheMiss

template<class KEYTYPE , class VALUETYPE >
int Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::m_cacheMiss
mutableprivate

total number of times the cache has not contained the requested information

Definition at line 148 of file Cache.h.

◆ m_mutex

template<class KEYTYPE , class VALUETYPE >
std::mutex Mantid::Kernel::Cache< KEYTYPE, VALUETYPE >::m_mutex
mutableprivate

internal mutex

Definition at line 152 of file Cache.h.


The documentation for this class was generated from the following files: