bool Insert(const key_type& key, const value_type& value, value_type* erase_value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); bool erased_old = false; if (found != m_entry_map.end()) { erased_old = true; if (NULL != erase_value) { (*erase_value) = (*found->second); } m_cache_list.erase(found->second); } m_cache_list.push_front(std::make_pair(key, value)); m_entry_map[key] = m_cache_list.begin(); if (m_entry_map.size() > m_max_size) { if (NULL != erase_value) { (*erase_value) = m_cache_list.back(); } m_entry_map.erase(m_cache_list.back().first); m_cache_list.pop_back(); erased_old = true; } return erased_old; }
bool Peek(const key_type& key, value_type& value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); if (found != m_entry_map.end()) { typename CacheList::iterator list_it = found->second; value = list_it->second; return true; } return false; }
bool Get(const key_type& key, value_type& value) { typename CacheEntryMap::iterator found = m_entry_map.find(key); if (found != m_entry_map.end()) { typename CacheList::iterator list_it = found->second; value = list_it->second; m_cache_list.erase(list_it); m_cache_list.push_front(std::make_pair(key, value)); m_entry_map[key] = m_cache_list.begin(); return true; } return false; }
bool GetLRUElement(CacheEntry& value, bool remove) { if (m_cache_list.empty()) { return false; } value = m_cache_list.back(); if (remove) { m_entry_map.erase(value.first); m_cache_list.pop_back(); } return true; }
bool GetLRUElement(value_type& value, bool remove) { if (m_cache_list.empty()) { return false; } CacheEntry & entry = m_cache_list.back(); value = entry.second; if (remove) { m_entry_map.erase(entry.first); m_cache_list.pop_back(); } return true; }
bool Contains(const key_type& key) { typename CacheEntryMap::iterator found = m_entry_map.find(key); return found != m_entry_map.end(); }
size_t Size() { return m_entry_map.size(); }
void Clear() { m_cache_list.clear(); m_entry_map.clear(); }