aboutsummaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-08-23 13:52:52 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-08-26 12:50:26 +0000
commitfdefa3786a3f1559786348a3ec91762771714a8c (patch)
tree6e81812d0c1fa36c1064f20d7255fbd5268e76cd /staging_vespalib
parent7651ac2985121e0fe86f47ea9289a56ca04d84d8 (diff)
provide callback when objects are actually remove/inserted to the lru.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h
index 993163a82cd..d0fb4259b30 100644
--- a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h
+++ b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h
@@ -120,7 +120,11 @@ public:
* Object is then put at head of LRU list.
*/
insert_result insert(const K & key, const V & value) {
- return insert(value_type(key, LV(value)));
+ insert_result res = insert(value_type(key, LV(value)));
+ if (res.second) {
+ onInsert(key);
+ }
+ return res;
}
/**
@@ -155,6 +159,12 @@ public:
(void) v;
return (size() > capacity());
}
+ virtual void onRemove(const K & key) {
+ (void) key;
+ }
+ virtual void onInsert(const K & key) {
+ (void) key;
+ }
/**
* Method for testing that internal consitency is good.
@@ -255,6 +265,7 @@ void
lrucache_map<P>::erase(const K & key) {
internal_iterator it = HashTable::find(key);
if (it != HashTable::end()) {
+ onRemove(key);
LV & v = it->second;
if (v._prev != LinkedValueBase::npos) {
HashTable::getByInternalIndex(v._prev).second._next = v._next;