CachedRegionTracker
@UnstableApi
public final class CachedRegionTracker implements Cache.Listener
Utility class for efficiently tracking regions of data that are stored in a Cache for a given cache key.
Summary
Constants |
|
|---|---|
static final int |
CACHED_TO_END = -2 |
static final int |
NOT_CACHED = -1 |
Public constructors |
|---|
CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) |
Public methods |
|
|---|---|
synchronized int |
getRegionEndTimeMs(long byteOffset)When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region. |
synchronized void |
onSpanAdded(Cache cache, CacheSpan span)Called when a |
synchronized void |
onSpanRemoved(Cache cache, CacheSpan span)Called when a |
void |
onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)Called when an existing |
void |
release() |
Constants
Public constructors
Public methods
getRegionEndTimeMs
synchronized public int getRegionEndTimeMs(long byteOffset)
When provided with a byte offset, this method locates the cached region within which the offset falls, and returns the approximate end position in milliseconds of that region. If the byte offset does not fall within a cached region then NOT_CACHED is returned. If the cached region extends to the end of the stream, CACHED_TO_END is returned.
| Parameters | |
|---|---|
long byteOffset |
The byte offset in the underlying stream. |
| Returns | |
|---|---|
int |
The end position of the corresponding cache region, |
onSpanAdded
synchronized public void onSpanAdded(Cache cache, CacheSpan span)
Called when a CacheSpan is added to the cache.
onSpanRemoved
synchronized public void onSpanRemoved(Cache cache, CacheSpan span)
Called when a CacheSpan is removed from the cache.
onSpanTouched
public void onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)
Called when an existing CacheSpan is touched, causing it to be replaced. The new CacheSpan is guaranteed to represent the same data as the one it replaces, however file and lastTouchTimestamp may have changed.
Note that for span replacement, onSpanAdded and onSpanRemoved are not called in addition to this method.