mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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.
|
* @throws CacheException If renaming of the underlying span file failed.
|
||||||
*/
|
*/
|
||||||
public SimpleCacheSpan touch(SimpleCacheSpan cacheSpan) throws CacheException {
|
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);
|
SimpleCacheSpan newCacheSpan = cacheSpan.copyWithUpdatedLastAccessTime(id);
|
||||||
// Rename the cache file
|
|
||||||
if (!cacheSpan.file.renameTo(newCacheSpan.file)) {
|
if (!cacheSpan.file.renameTo(newCacheSpan.file)) {
|
||||||
throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file
|
throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file
|
||||||
+ " failed.");
|
+ " 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);
|
cachedSpans.add(newCacheSpan);
|
||||||
return newCacheSpan;
|
return newCacheSpan;
|
||||||
}
|
}
|
||||||
|
@ -232,10 +232,16 @@ public final class SimpleCache implements Cache {
|
|||||||
|
|
||||||
// Read case.
|
// Read case.
|
||||||
if (cacheSpan.isCached) {
|
if (cacheSpan.isCached) {
|
||||||
// Obtain a new span with updated last access timestamp.
|
try {
|
||||||
SimpleCacheSpan newCacheSpan = index.get(key).touch(cacheSpan);
|
// Obtain a new span with updated last access timestamp.
|
||||||
notifySpanTouched(cacheSpan, newCacheSpan);
|
SimpleCacheSpan newCacheSpan = index.get(key).touch(cacheSpan);
|
||||||
return newCacheSpan;
|
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);
|
CachedContent cachedContent = index.getOrAdd(key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user