Stay organized with collections Save and categorize content based on your preferences.

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
static final int

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 CacheSpan is added to the cache.

synchronized 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 touched, causing it to be replaced.

void

Constants

CACHED_TO_END

public static final int CACHED_TO_END = -2

NOT_CACHED

public static final int NOT_CACHED = -1

Public constructors

CachedRegionTracker

public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex)

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, NOT_CACHED, or CACHED_TO_END.

onSpanAdded

synchronized public void onSpanAdded(Cache cache, CacheSpan span)

Called when a CacheSpan is added to the cache.

Parameters
Cache cache

The source of the event.

CacheSpan span

The added CacheSpan.

onSpanRemoved

synchronized public void onSpanRemoved(Cache cache, CacheSpan span)

Called when a CacheSpan is removed from the cache.

Parameters
Cache cache

The source of the event.

CacheSpan span

The removed CacheSpan.

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.

Parameters
Cache cache

The source of the event.

CacheSpan oldSpan

The old CacheSpan, which has been removed from the cache.

CacheSpan newSpan

The new CacheSpan, which has been added to the cache.

release

public void release()