Class BoundedLocalCache.BoundedPolicy.BoundedEviction
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.BoundedLocalCache.BoundedPolicy.BoundedEviction
-
- All Implemented Interfaces:
Policy.Eviction<K,V>
- Enclosing class:
- BoundedLocalCache.BoundedPolicy<K,V>
final class BoundedLocalCache.BoundedPolicy.BoundedEviction extends java.lang.Object implements Policy.Eviction<K,V>
-
-
Constructor Summary
Constructors Constructor Description BoundedEviction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<K,V>
coldest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.long
getMaximum()
Returns the maximum total weighted or unweighted size of this cache, depending on how the cache was constructed.java.util.Map<K,V>
hottest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.boolean
isWeighted()
Returns whether the cache is bounded by a maximum size or maximum weight.void
setMaximum(long maximum)
Specifies the maximum total size of this cache.java.util.OptionalLong
weightedSize()
Returns the approximate accumulated weight of entries in this cache.java.util.OptionalInt
weightOf(K key)
Returns the weight of the entry.
-
-
-
Method Detail
-
isWeighted
public boolean isWeighted()
Description copied from interface:Policy.Eviction
Returns whether the cache is bounded by a maximum size or maximum weight.- Specified by:
isWeighted
in interfacePolicy.Eviction<K,V>
- Returns:
- if the size bounding takes into account the entry's weight
-
weightOf
public java.util.OptionalInt weightOf(@Nonnull K key)
Description copied from interface:Policy.Eviction
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 theOptionalInt
will be empty.- Specified by:
weightOf
in interfacePolicy.Eviction<K,V>
- Parameters:
key
- the key for the entry being queried- Returns:
- the weight if the entry is present in the cache
-
weightedSize
public java.util.OptionalLong weightedSize()
Description copied from interface:Policy.Eviction
Returns the approximate accumulated weight of entries in this cache. If this cache does not use a weighted size bound, then theOptionalLong
will be empty.- Specified by:
weightedSize
in interfacePolicy.Eviction<K,V>
- Returns:
- the combined weight of the values in this cache
-
getMaximum
public long getMaximum()
Description copied from interface:Policy.Eviction
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 inspectingPolicy.Eviction.isWeighted()
.- Specified by:
getMaximum
in interfacePolicy.Eviction<K,V>
- Returns:
- the maximum size bounding, which may be either weighted or unweighted
-
setMaximum
public void setMaximum(long maximum)
Description copied from interface:Policy.Eviction
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.
- Specified by:
setMaximum
in interfacePolicy.Eviction<K,V>
- Parameters:
maximum
- the maximum, interpreted as weighted or unweighted size depending on how this cache was constructed
-
coldest
public java.util.Map<K,V> coldest(int limit)
Description copied from interface:Policy.Eviction
Returns an unmodifiable snapshotMap
view 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.
- Specified by:
coldest
in interfacePolicy.Eviction<K,V>
- Parameters:
limit
- the maximum size of the returned map (useInteger.MAX_VALUE
to disregard the limit)- Returns:
- a snapshot view of the cache from coldest entry to the hottest
-
hottest
public java.util.Map<K,V> hottest(int limit)
Description copied from interface:Policy.Eviction
Returns an unmodifiable snapshotMap
view 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.
- Specified by:
hottest
in interfacePolicy.Eviction<K,V>
- Parameters:
limit
- the maximum size of the returned map (useInteger.MAX_VALUE
to disregard the limit)- Returns:
- a snapshot view of the cache from hottest entry to the coldest
-
-