LeastRecentlyUsedCacheEvictor


@UnstableApi
public final class LeastRecentlyUsedCacheEvictor implements CacheEvictor


Evicts least recently used cache files first.

Summary

Public constructors

Public methods

void

Called when cache has been initialized.

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

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

Called when a writer starts writing to the cache.

boolean

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

Public constructors

LeastRecentlyUsedCacheEvictor

public LeastRecentlyUsedCacheEvictor(long maxBytes)

Public methods

onCacheInitialized

public void onCacheInitialized()

Called when cache has been initialized.

onSpanAdded

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

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.

onStartFile

public 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

public 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.