Interface Policy.Eviction<K,V>
- All Known Implementing Classes:
BoundedLocalCache.BoundedPolicy.BoundedEviction
public static interface Policy.Eviction<K,V>
The low-level operations for a cache with a size-based eviction policy.
-
Method Summary
Modifier and TypeMethodDescriptioncoldest(@NonNegative int limit) Returns an unmodifiable snapshotMapview of the cache with ordered traversal.@NonNegative longReturns the maximum total weighted or unweighted size of this cache, depending on how the cache was constructed.hottest(@NonNegative int limit) Returns an unmodifiable snapshotMapview of the cache with ordered traversal.booleanReturns whether the cache is bounded by a maximum size or maximum weight.voidsetMaximum(@NonNegative long maximum) Specifies the maximum total size of this cache.@NonNull OptionalLongReturns the approximate accumulated weight of entries in this cache.default @NonNull OptionalIntReturns the weight of the entry.
-
Method Details
-
isWeighted
boolean isWeighted()Returns whether the cache is bounded by a maximum size or maximum weight.- Returns:
- if the size bounding takes into account the entry's weight
-
weightOf
Returns the weight of the entry. If this cache does not use a weighted size bound or does not support querying for the entry's weight, then theOptionalIntwill be empty.- Parameters:
key- the key for the entry being queried- Returns:
- the weight if the entry is present in the cache
-
weightedSize
@NonNull OptionalLong weightedSize()Returns the approximate accumulated weight of entries in this cache. If this cache does not use a weighted size bound, then theOptionalLongwill be empty.- Returns:
- the combined weight of the values in this cache
-
getMaximum
@NonNegative long getMaximum()Returns the maximum total weighted or unweighted size of this cache, depending on how the cache was constructed. This value can be best understood by inspectingisWeighted().- Returns:
- the maximum size bounding, which may be either weighted or unweighted
-
setMaximum
void setMaximum(@NonNegative long maximum) Specifies the maximum total size of this cache. This value may be interpreted as the weighted or unweighted threshold size based on how this cache was constructed. If the cache currently exceeds the new maximum size this operation eagerly evict entries until the cache shrinks to the appropriate size.Note that some implementations may have an internal inherent bound on the maximum total size. If the value specified exceeds that bound, then the value is set to the internal maximum.
- Parameters:
maximum- the maximum, interpreted as weighted or unweighted size depending on how this cache was constructed- Throws:
IllegalArgumentException- if the maximum size specified is negative
-
coldest
Returns an unmodifiable snapshotMapview of the cache with ordered traversal. The order of iteration is from the entries least likely to be retained (coldest) to the entries most likely to be retained (hottest). This order is determined by the eviction policy's best guess at the time of creating this snapshot view.Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
- Parameters:
limit- the maximum size of the returned map (useInteger.MAX_VALUEto disregard the limit)- Returns:
- a snapshot view of the cache from coldest entry to the hottest
-
hottest
Returns an unmodifiable snapshotMapview of the cache with ordered traversal. The order of iteration is from the entries most likely to be retained (hottest) to the entries least likely to be retained (coldest). This order is determined by the eviction policy's best guess at the time of creating this snapshot view.Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
- Parameters:
limit- the maximum size of the returned map (useInteger.MAX_VALUEto disregard the limit)- Returns:
- a snapshot view of the cache from hottest entry to the coldest
-