[error prone] Suppress NonAtomicVolatileUpdate in SimpleLruCache
We don't need to update time atomically since it's only used to order cache entries in LRU order. Change-Id: I756fa6d90b180c519bf52925f134763744f2c1f1 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
1fd09a19a2
commit
d4752e2900
|
@ -162,7 +162,7 @@ public SimpleLruCache(int maxSize, float purgeFactor) {
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
Entry<K, V> entry = map.get(key);
|
Entry<K, V> entry = map.get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.lastAccessed = ++time;
|
entry.lastAccessed = tick();
|
||||||
return entry.value;
|
return entry.value;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -186,13 +186,18 @@ public V get(Object key) {
|
||||||
* if the specified key or value is null
|
* if the specified key or value is null
|
||||||
*/
|
*/
|
||||||
public V put(@NonNull K key, @NonNull V value) {
|
public V put(@NonNull K key, @NonNull V value) {
|
||||||
map.put(key, new Entry<>(key, value, ++time));
|
map.put(key, new Entry<>(key, value, tick()));
|
||||||
if (map.size() > maximumSize) {
|
if (map.size() > maximumSize) {
|
||||||
purge();
|
purge();
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NonAtomicVolatileUpdate")
|
||||||
|
private long tick() {
|
||||||
|
return ++time;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current size of this cache
|
* Returns the current size of this cache
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue