12#include "MantidKernel/DllConfig.h"
30 Cache() : m_cacheHit(0), m_cacheMiss(0), m_cacheMap(), m_mutex() {}
37 : m_cacheHit(src.m_cacheHit), m_cacheMiss(src.m_cacheMiss), m_cacheMap(src.m_cacheMap),
48 m_cacheHit =
rhs.m_cacheHit;
49 m_cacheMiss =
rhs.m_cacheMiss;
50 m_cacheMap =
rhs.m_cacheMap;
57 std::lock_guard<std::mutex> lock(m_mutex);
64 int size() {
return static_cast<int>(m_cacheMap.size()); }
73 double hitRatio = 0.0;
74 if ((m_cacheHit + m_cacheMiss) > 0) {
75 hitRatio = 100.0 * (m_cacheHit * 1.0) / (m_cacheHit + m_cacheMiss);
86 std::lock_guard<std::mutex> lock(m_mutex);
87 m_cacheMap[key] =
value;
100 bool found = getCacheNoStats(key,
value);
110 return getCacheNoStats(key,
value);
120 std::lock_guard<std::mutex> lock(m_mutex);
121 m_cacheMap.erase(key);
133 std::lock_guard<std::mutex> lock(m_mutex);
134 auto it_found = m_cacheMap.find(key);
135 bool isValid = it_found != m_cacheMap.end();
138 value = it_found->second;
const std::vector< double > & rhs
double value
The value of the point.
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Cache is a generic caching storage class.
Cache()
No-arg Constructor.
void setCache(const KEYTYPE &key, const VALUETYPE &value)
Inserts/updates a cached value with the given key.
void clear()
Clears the cache.
int m_cacheMiss
total number of times the cache has not contained the requested information
void removeCache(const KEYTYPE &key)
Attempts to remove a value from the cache.
std::map< KEYTYPE, VALUETYPE > m_cacheMap
internal cache map
double hitRatio()
total number of times the cache has contained the requested information/the total number of requests
int missCount()
total number of times the cache has contained the requested information
std::mutex m_mutex
internal mutex
Cache< KEYTYPE, VALUETYPE > & operator=(const Cache< KEYTYPE, VALUETYPE > &rhs)
Copy-assignment operator as we have a non-default copy constructor.
Cache(const Cache< KEYTYPE, VALUETYPE > &src)
Copy constructor (mutex cannot be copied)
bool getCacheNoStats(const KEYTYPE key, VALUETYPE &value) const
Attempts to retrieve a value from the cache.
int size()
The number of cache entries.
typename std::map< KEYTYPE, VALUETYPE >::const_iterator CacheMapConstIterator
const_iterator typedef
int hitCount()
total number of times the cache has contained the requested information
bool getCache(const KEYTYPE &key, VALUETYPE &value) const
Attempts to retrieve a value from the cache, with optional cache stats tracking.
typename std::map< KEYTYPE, VALUETYPE >::iterator CacheMapIterator
iterator typedef
int m_cacheHit
total number of times the cache has contained the requested information
Helper class which provides the Collimation Length for SANS instruments.