Class BoundedLocalCache.BoundedPolicy.BoundedExpireAfterAccess
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.BoundedLocalCache.BoundedPolicy.BoundedExpireAfterAccess
-
- All Implemented Interfaces:
Policy.Expiration<K,V>
- Enclosing class:
- BoundedLocalCache.BoundedPolicy<K,V>
final class BoundedLocalCache.BoundedPolicy.BoundedExpireAfterAccess extends java.lang.Object implements Policy.Expiration<K,V>
-
-
Constructor Summary
Constructors Constructor Description BoundedExpireAfterAccess()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.OptionalLong
ageOf(K key, java.util.concurrent.TimeUnit unit)
Returns the age of the entry based on the expiration policy.long
getExpiresAfter(java.util.concurrent.TimeUnit unit)
Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound.java.util.Map<K,V>
oldest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.void
setExpiresAfter(long duration, java.util.concurrent.TimeUnit unit)
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed based.java.util.Map<K,V>
youngest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.
-
-
-
Method Detail
-
ageOf
public java.util.OptionalLong ageOf(K key, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.Expiration
Returns the age of the entry based on the expiration policy. The entry's age is the cache's estimate of the amount of time since the entry's expiration was last reset.An expiration policy uses the age to determine if an entry is fresh or stale by comparing it to the freshness lifetime. This is calculated as
fresh = freshnessLifetime > age
wherefreshnessLifetime = expires - currentTime
.- Specified by:
ageOf
in interfacePolicy.Expiration<K,V>
- Parameters:
key
- the key for the entry being queriedunit
- the unit thatage
is expressed in- Returns:
- the age if the entry is present in the cache
-
getExpiresAfter
public long getExpiresAfter(java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.Expiration
Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound. An entry is considered fresh if its age is less than this duration, and stale otherwise. The expiration policy determines when the entry's age is reset.- Specified by:
getExpiresAfter
in interfacePolicy.Expiration<K,V>
- Parameters:
unit
- the unit that duration is expressed in- Returns:
- the length of time after which an entry should be automatically removed
-
setExpiresAfter
public void setExpiresAfter(long duration, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.Expiration
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed based. The expiration policy determines when the entry's age is reset.- Specified by:
setExpiresAfter
in interfacePolicy.Expiration<K,V>
- Parameters:
duration
- the length of time after which an entry should be automatically removedunit
- the unit thatduration
is expressed in
-
oldest
public java.util.Map<K,V> oldest(int limit)
Description copied from interface:Policy.Expiration
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal. The order of iteration is from the entries most likely to expire (oldest) to the entries least likely to expire (youngest). This order is determined by the expiration 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:
oldest
in interfacePolicy.Expiration<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 oldest entry to the youngest
-
youngest
public java.util.Map<K,V> youngest(int limit)
Description copied from interface:Policy.Expiration
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal. The order of iteration is from the entries least likely to expire (youngest) to the entries most likely to expire (oldest). This order is determined by the expiration 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:
youngest
in interfacePolicy.Expiration<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 youngest entry to the oldest
-
-