@UnstableApi
public interface CacheEvictor extends Cache.Listener

Known direct subclasses
LeastRecentlyUsedCacheEvictor

Evicts least recently used cache files first.

NoOpCacheEvictor

Evictor that doesn't ever evict cache files.


Evicts data from a Cache. Implementations should call removeSpan to evict cache entries based on their eviction policies.

Summary

Public methods

abstract void

Called when cache has been initialized.

abstract void
onStartFile(Cache cache, String key, long position, long length)

Called when a writer starts writing to the cache.

abstract boolean

Returns whether the evictor requires the Cache to touch CacheSpans when it accesses them.

Inherited methods

From androidx.media3.datasource.cache.Cache.Listener
abstract void
onSpanAdded(Cache cache, CacheSpan span)

Called when a CacheSpan is added to the cache.

abstract void
onSpanRemoved(Cache cache, CacheSpan span)

Called when a CacheSpan is removed from the cache.

abstract void
onSpanTouched(Cache cache, CacheSpan oldSpan, CacheSpan newSpan)

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

Public methods

onCacheInitialized

abstract void onCacheInitialized()

Called when cache has been initialized.

onStartFile

abstract void onStartFile(Cache cache, String key, long position, long length)

Called when a writer starts writing to the cache.

Parameters
Cache cache

The source of the event.

String key

The key being written.

long position

The starting position of the data being written.

long length

The length of the data being written, or LENGTH_UNSET if unknown.

requiresCacheSpanTouches

abstract boolean requiresCacheSpanTouches()

Returns whether the evictor requires the Cache to touch CacheSpans when it accesses them. Implementations that do not use lastTouchTimestamp should return false.