diff options
author | Henning Baldersheim <balder@oath.com> | 2018-07-19 14:00:27 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-07-19 14:00:27 +0200 |
commit | 81914f5a56ceb33001179c172f22278398c86a51 (patch) | |
tree | 1d8e7a1e137eee94e8275e72085ead1a144cd644 /staging_vespalib | |
parent | 9df684ab0857b573443c00ac7cf1007822d17dfc (diff) |
Add control of cache update policy when an item changes value.
Diffstat (limited to 'staging_vespalib')
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/stllike/cache.h | 2 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/stllike/cache.hpp | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/stllike/cache.h b/staging_vespalib/src/vespa/vespalib/stllike/cache.h index 3d5ab155877..6b3cec659aa 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/cache.h +++ b/staging_vespalib/src/vespa/vespalib/stllike/cache.h @@ -101,7 +101,7 @@ public: * Update the cache and write through to backing store. * Object is then put at head of LRU list. */ - void write(const K & key, const V & value); + void write(const K & key, V value); /** * Tell if an object with given key exists in the cache. diff --git a/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp b/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp index a8c7d16473c..1ba168fa77b 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp +++ b/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp @@ -120,16 +120,17 @@ cache<P>::read(const K & key) template< typename P > void -cache<P>::write(const K & key, const V & value) +cache<P>::write(const K & key, V value) { vespalib::LockGuard storeGuard(getLock(key)); + _store.write(key, value); { vespalib::LockGuard guard(_hashLock); - (*this)[key] = value; - _sizeBytes += calcSize(key, value); + size_t sz = calcSize(key, value); + (*this)[key] = std::move(value); + _sizeBytes += sz; _write++; } - _store.write(key, value); } template< typename P > |