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
This commit is contained in:
parent
9f0303b079
commit
509be44fe8
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user