CachedRegionTracker


@UnstableApi
class CachedRegionTracker : Cache.Listener


Utility class for efficiently tracking regions of data that are stored in a Cache for a given cache key.

Summary

Constants

const Int
const Int

Public constructors

CachedRegionTracker(cache: Cache!, cacheKey: String!, chunkIndex: ChunkIndex!)

Public functions

synchronized Int
getRegionEndTimeMs(byteOffset: Long)

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 Unit
onSpanAdded(cache: Cache!, span: CacheSpan!)

Called when a CacheSpan is added to the cache.

synchronized Unit
onSpanRemoved(cache: Cache!, span: CacheSpan!)

Called when a CacheSpan is removed from the cache.

Unit
onSpanTouched(cache: Cache!, oldSpan: CacheSpan!, newSpan: CacheSpan!)

Called when an existing CacheSpan is touched, causing it to be replaced.

Unit

Constants

CACHED_TO_END

const val CACHED_TO_END = -2: Int

NOT_CACHED

const val NOT_CACHED = -1: Int

Public constructors

CachedRegionTracker

CachedRegionTracker(cache: Cache!, cacheKey: String!, chunkIndex: ChunkIndex!)

Public functions

getRegionEndTimeMs

synchronized fun getRegionEndTimeMs(byteOffset: Long): Int

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
byteOffset: Long

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 fun onSpanAdded(cache: Cache!, span: CacheSpan!): Unit

Called when a CacheSpan is added to the cache.

Parameters
cache: Cache!

The source of the event.

span: CacheSpan!

The added CacheSpan.

onSpanRemoved

synchronized fun onSpanRemoved(cache: Cache!, span: CacheSpan!): Unit

Called when a CacheSpan is removed from the cache.

Parameters
cache: Cache!

The source of the event.

span: CacheSpan!

The removed CacheSpan.

onSpanTouched

fun onSpanTouched(cache: Cache!, oldSpan: CacheSpan!, newSpan: CacheSpan!): Unit

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.

oldSpan: CacheSpan!

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

newSpan: CacheSpan!

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

release

fun release(): Unit