Skip to content

Commit

Permalink
Avoid caching invalid entity (null entiry) into memory, thus avoiding…
Browse files Browse the repository at this point in the history
… triggering additional evictions
  • Loading branch information
“shenghui361” committed Jul 14, 2021
1 parent f3e40ba commit 05073b4
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,22 @@ private Optional<V> getSkipCache(K key) {
* @param value the value
*/
public void put(K key, V value) {
mMap.compute(key, (k, entry) -> {
onPut(key, value);
if (entry == null && cacheIsFull()) {
writeToBackingStore(key, value);
return null;
}
if (entry == null || entry.mValue == null) {
onCacheUpdate(key, value);
return new Entry(key, value);
}
onPut(key, value);
Entry entry = mMap.get(key);
if(entry == null && cacheIsFull()) {
writeToBackingStore(key, value);
return;
}

if (entry == null || entry.mValue == null) {
onCacheUpdate(key, value);
entry = new Entry(key, value);
} else {
entry.mValue = value;
entry.mReferenced = true;
entry.mDirty = true;
return entry;
});
}
mMap.put(key, entry);
wakeEvictionThreadIfNecessary();
}

Expand Down

0 comments on commit 05073b4

Please sign in to comment.