Interface Policy.FixedExpiration<K,V>
- Type Parameters:
K- the type of keysV- the type of values
-
Method Summary
Modifier and TypeMethodDescriptionReturns the age of the entry based on the expiration policy.Returns the age of the entry based on the expiration policy.default DurationReturns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound.longgetExpiresAfter(TimeUnit unit) Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound.oldest(int limit) Returns an unmodifiable snapshotMapview of the cache with ordered traversal.default <T> TReturns the computed result from the ordered traversal of the cache entries.voidsetExpiresAfter(long duration, TimeUnit unit) Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed.default voidsetExpiresAfter(Duration duration) Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed.youngest(int limit) Returns an unmodifiable snapshotMapview of the cache with ordered traversal.default <T> TReturns the computed result from the ordered traversal of the cache entries.
-
Method Details
-
ageOf
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 > agewherefreshnessLifetime = expires - currentTime.- Parameters:
key- the key for the entry being queriedunit- the unit thatageis expressed in- Returns:
- the age if the entry is present in the cache
- Throws:
NullPointerException- if the specified key is null
-
ageOf
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 > agewherefreshnessLifetime = expires - currentTime.- Parameters:
key- the key for the entry being queried- Returns:
- the age if the entry is present in the cache
- Throws:
NullPointerException- if the specified key is null
-
getExpiresAfter
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.- Parameters:
unit- the unit that duration is expressed in- Returns:
- the length of time after which an entry should be automatically removed
- Throws:
NullPointerException- if the unit is null
-
getExpiresAfter
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.- Returns:
- the length of time after which an entry should be automatically removed
-
setExpiresAfter
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed. The expiration policy determines when the entry's age is reset.- Parameters:
duration- the length of time after which an entry should be automatically removedunit- the unit thatdurationis expressed in- Throws:
IllegalArgumentException- ifdurationis negativeNullPointerException- if the unit is null
-
setExpiresAfter
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed. The expiration policy determines when the entry's age is reset.- Parameters:
duration- the length of time after which an entry should be automatically removed- Throws:
IllegalArgumentException- ifdurationis negativeNullPointerException- if the duration is null
-
oldest
Returns an unmodifiable snapshotMapview 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.
- Parameters:
limit- the maximum size of the returned map (useInteger.MAX_VALUEto disregard the limit)- Returns:
- a snapshot view of the cache from the oldest entry to the youngest
- Throws:
IllegalArgumentException- if the limit specified is negative
-
oldest
Returns the computed result from the ordered traversal of the cache entries. The oorder 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 computation.Usage example:
List<K> tenOldestKeys = cache.policy().expireAfterWrite().orElseThrow() .oldest(stream -> stream.map(Map.Entry::getKey).limit(10).toList());Beware that this computation is performed within the eviction policy's exclusive lock, so the computation should be short and simple. While the computation is in progress further eviction maintenance will be halted.
- Type Parameters:
T- the type of the result of the mappingFunction- Parameters:
mappingFunction- the mapping function to compute a value- Returns:
- the computed value
- Throws:
NullPointerException- if the mappingFunction is nullRuntimeException- or Error if the mappingFunction does so
-
youngest
Returns an unmodifiable snapshotMapview 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.
- Parameters:
limit- the maximum size of the returned map (useInteger.MAX_VALUEto disregard the limit)- Returns:
- a snapshot view of the cache from the youngest entry to the oldest
- Throws:
IllegalArgumentException- if the limit specified is negative
-
youngest
Returns the computed result from the ordered traversal of the cache entries. 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 computation.Usage example:
List<K> tenYoungestKeys = cache.policy().expireAfterWrite().orElseThrow() .youngest(stream -> stream.map(Map.Entry::getKey).limit(10).toList());Beware that this computation is performed within the eviction policy's exclusive lock, so the computation should be short and simple. While the computation is in progress further eviction maintenance will be halted.
- Type Parameters:
T- the type of the result of the mappingFunction- Parameters:
mappingFunction- the mapping function to compute a value- Returns:
- the computed value
- Throws:
NullPointerException- if the mappingFunction is nullRuntimeException- or Error if the mappingFunction does so
-