8 #define LRUCACHE_DEBUG 1
15 CacheStats(
unsigned entries,
unsigned maxEntries,
unsigned queries,
float hitRatio )
40 template<
typename K,
typename T,
typename COMPARE=std::less<K> >
56 virtual void operator()(
const K& key,
const T& value) =0;
60 typedef typename std::list<K>::iterator
lru_iter;
63 typedef typename std::map<K, map_value_type>
map_type;
97 void insert(
const K& key,
const T& value ) {
107 bool get(
const K& key, Record& out ) {
118 bool has(
const K& key ) {
184 if ( mi !=
_map.end() ) {
186 _lru.erase(valType.second);
187 valType.first = value;
188 _lru.push_back( key );
189 valType.second =
_lru.end();
194 std::cout <<
"Cache hit: " << key << std::endl;
199 _lru.push_back( key );
201 _map[key] = std::make_pair(value, last);
206 std::cout <<
"Cache insert: " << key << std::endl;
212 for(
unsigned i=0; i <
_buf; ++i ) {
213 const K& key =
_lru.front();
217 std::cout <<
"Ejected: " <<
_map.find(key)->second.first.get() << std::endl;
229 if ( mi !=
_map.end() ) {
231 _lru.erase(valType.second);
232 _lru.push_back( key );
234 valType.second = new_iter;
236 result._value = valType.first;
237 result._valid =
true;
242 return _map.find( key ) !=
_map.end();
247 if ( mi !=
_map.end() ) {
248 _lru.erase( mi->second.second );
261 _max = std::max(max, 10u);
264 const K& key =
_lru.front();
272 f(i->first, i->second.first);