7 #ifndef SIMPLELRUCACHE_H 8 #define SIMPLELRUCACHE_H 18 template <
class KEY,
class VALUE,
class HASH,
class EQUAL>
24 typedef boost::unordered_map<KEY, typename key_list::iterator, HASH, EQUAL>
map_type;
40 void put(
const KEY& key,
const VALUE& value) {
41 cacheList.push_front(std::make_pair(key, value));
42 cacheMap[key] = cacheList.begin();
44 if ((int32_t)cacheList.size() >
cacheSize) {
45 cacheMap.erase(cacheList.back().first);
50 VALUE
get(
const KEY& key) {
51 map_iterator find = cacheMap.find(key);
52 if (find == cacheMap.end()) {
56 VALUE value(find->second->second);
57 cacheList.erase(find->second);
58 cacheList.push_front(std::make_pair(key, value));
59 cacheMap[key] = cacheList.begin();
65 return (cacheMap.find(key) != cacheMap.end());
69 return (int32_t)cacheList.size();
73 return cacheList.begin();
76 const_iterator
end()
const {
77 return cacheList.end();
int32_t cacheSize
Definition: SimpleLRUCache.h:35
bool contains(const KEY &key) const
Definition: SimpleLRUCache.h:64
boost::unordered_map< KEY, typename key_list::iterator, HASH, EQUAL > map_type
Definition: SimpleLRUCache.h:24
std::pair< KEY, VALUE > key_value
Definition: SimpleLRUCache.h:21
General purpose LRU cache map. Accessing an entry will keep the entry cached. get(const KEY&) and put...
Definition: SimpleLRUCache.h:19
map_type::const_iterator map_iterator
Definition: SimpleLRUCache.h:25
key_list::const_iterator const_iterator
Definition: SimpleLRUCache.h:23
Base class for all Lucene classes.
Definition: LuceneObject.h:31
std::list< key_value > key_list
Definition: SimpleLRUCache.h:22
Definition: AbstractAllTermDocs.h:12
const_iterator end() const
Definition: SimpleLRUCache.h:76
SimpleLRUCache(int32_t cacheSize)
Definition: SimpleLRUCache.h:27
virtual ~SimpleLRUCache()
Definition: SimpleLRUCache.h:31
key_list cacheList
Definition: SimpleLRUCache.h:36
void put(const KEY &key, const VALUE &value)
Definition: SimpleLRUCache.h:40
const_iterator begin() const
Definition: SimpleLRUCache.h:72
map_type cacheMap
Definition: SimpleLRUCache.h:37
int32_t size() const
Definition: SimpleLRUCache.h:68