public final class CachedRegionTracker extends java.lang.Object implements Cache.Listener
Cache
for a given cache key.Modifier and Type | Field and Description |
---|---|
static int |
CACHED_TO_END |
static int |
NOT_CACHED |
Constructor and Description |
---|
CachedRegionTracker(Cache cache,
java.lang.String cacheKey,
ChunkIndex chunkIndex) |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
onSpanAdded(Cache cache,
CacheSpan span)
Called when a
CacheSpan is added to the cache. |
void |
onSpanRemoved(Cache cache,
CacheSpan span)
Called when a
CacheSpan is removed from the cache. |
void |
onSpanTouched(Cache cache,
CacheSpan oldSpan,
CacheSpan newSpan)
Called when an existing
CacheSpan is accessed, causing it to be replaced. |
void |
release() |
public static final int NOT_CACHED
public static final int CACHED_TO_END
public CachedRegionTracker(Cache cache, java.lang.String cacheKey, ChunkIndex chunkIndex)
public void release()
public int getRegionEndTimeMs(long byteOffset)
NOT_CACHED
is returned.
If the cached region extends to the end of the stream, CACHED_TO_END
is returned.byteOffset
- The byte offset in the underlying stream.NOT_CACHED
, or
CACHED_TO_END
.public void onSpanAdded(Cache cache, CacheSpan span)
Cache.Listener
CacheSpan
is added to the cache.onSpanAdded
in interface Cache.Listener
cache
- The source of the event.span
- The added CacheSpan
.public void onSpanRemoved(Cache cache, CacheSpan span)
Cache.Listener
CacheSpan
is removed from the cache.onSpanRemoved
in interface Cache.Listener
cache
- The source of the event.span
- The removed CacheSpan
.public void onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)
Cache.Listener
CacheSpan
is accessed, causing it to be replaced. The new
CacheSpan
is guaranteed to represent the same data as the one it replaces, however
CacheSpan.file
and CacheSpan.lastAccessTimestamp
may have changed.
Note that for span replacement, Cache.Listener.onSpanAdded(Cache, CacheSpan)
and
Cache.Listener.onSpanRemoved(Cache, CacheSpan)
are not called in addition to this method.
onSpanTouched
in interface Cache.Listener
cache
- The source of the event.oldSpan
- The old CacheSpan
, which has been removed from the cache.newSpan
- The new CacheSpan
, which has been added to the cache.