Commit 509be44f by eguven Committed by Oliver Woodman

Ignore cache span rename error

This happens rarely and SimpleCache can continue fine.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209759996
parent 9f0303b0
......@@ -185,16 +185,13 @@ import java.util.TreeSet;
* @throws CacheException If renaming of the underlying span file failed.
*/
public SimpleCacheSpan touch(SimpleCacheSpan cacheSpan) throws CacheException {
// Remove the old span from the in-memory representation.
Assertions.checkState(cachedSpans.remove(cacheSpan));
// Obtain a new span with updated last access timestamp.
SimpleCacheSpan newCacheSpan = cacheSpan.copyWithUpdatedLastAccessTime(id);
// Rename the cache file
if (!cacheSpan.file.renameTo(newCacheSpan.file)) {
throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file
+ " failed.");
}
// Add the updated span back into the in-memory representation.
// Replace the in-memory representation of the span.
Assertions.checkState(cachedSpans.remove(cacheSpan));
cachedSpans.add(newCacheSpan);
return newCacheSpan;
}
......
......@@ -232,10 +232,16 @@ public final class SimpleCache implements Cache {
// Read case.
if (cacheSpan.isCached) {
// Obtain a new span with updated last access timestamp.
SimpleCacheSpan newCacheSpan = index.get(key).touch(cacheSpan);
notifySpanTouched(cacheSpan, newCacheSpan);
return newCacheSpan;
try {
// Obtain a new span with updated last access timestamp.
SimpleCacheSpan newCacheSpan = index.get(key).touch(cacheSpan);
notifySpanTouched(cacheSpan, newCacheSpan);
return newCacheSpan;
} catch (CacheException e) {
// Ignore. In worst case the cache span is evicted early.
// This happens very rarely [Internal: b/38351639]
return cacheSpan;
}
}
CachedContent cachedContent = index.getOrAdd(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment