提交 b12bb799 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: simplify the cache API a bit

上级 1e391a6c
...@@ -136,6 +136,17 @@ public class CacheLongKeyLIRS<V> { ...@@ -136,6 +136,17 @@ public class CacheLongKeyLIRS<V> {
return e == null ? null : e.value; return e == null ? null : e.value;
} }
/**
* Add an entry to the cache using the average memory size.
*
* @param key the key (may not be null)
* @param value the value (may not be null)
* @return the old value, or null if there was no resident entry
*/
public V put(long key, V value) {
return put(key, value, sizeOf(value));
}
/** /**
* Add an entry to the cache. The entry may or may not exist in the * Add an entry to the cache. The entry may or may not exist in the
* cache yet. This method will usually mark unknown entries as cold and * cache yet. This method will usually mark unknown entries as cold and
...@@ -152,14 +163,14 @@ public class CacheLongKeyLIRS<V> { ...@@ -152,14 +163,14 @@ public class CacheLongKeyLIRS<V> {
} }
/** /**
* Add an entry to the cache using the average memory size. * Get the size of the given value. The default implementation returns the
* average memory as configured for this cache.
* *
* @param key the key (may not be null) * @param value the value
* @param value the value (may not be null) * @return the size
* @return the old value, or null if there was no resident entry
*/ */
public V put(long key, V value) { protected int sizeOf(V value) {
return put(key, value, averageMemory); return averageMemory;
} }
/** /**
......
...@@ -161,7 +161,19 @@ public class CacheLIRS<K, V> extends AbstractMap<K, V> implements Map<K, V> { ...@@ -161,7 +161,19 @@ public class CacheLIRS<K, V> extends AbstractMap<K, V> implements Map<K, V> {
* @return the old value, or null if there was no resident entry * @return the old value, or null if there was no resident entry
*/ */
public V put(K key, V value) { public V put(K key, V value) {
return put(key, value, averageMemory); return put(key, value, sizeOf(key, value));
}
/**
* Get the size of the given value. The default implementation returns the
* average memory as configured for this cache.
*
* @param key the key
* @param value the value
* @return the size
*/
protected int sizeOf(K key, V value) {
return averageMemory;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论