public class LRUExpiryStrategy extends Object implements ExpiryStrategy
CompositeKeyCache
and expires the
oldest elements first.
These are the basic semantics:
As the ExpiryStrategy.performExpiry(CacheIteratorFactory, TrackableCache, boolean, ExpiryPressure)
method is called, it's first checked
whether the given iterator represents its values in a last-recently-used order. If true, the oldest elements will be
evicted first, until enough space has been freed, a certain amount of elements have been evicted and also more then a
minimum bound. As an element is found thats younger then the minimumExpiryAge
the expiry will stop. If too
many elements are still left that should be evicted, expiry goes on until this not true any longer
ExpiryStrategy.ExpiryPressure
Constructor and Description |
---|
LRUExpiryStrategy() |
Modifier and Type | Method and Description |
---|---|
float |
getExpiryObjectCountRatio()
This returns the ratio how many elements dependent on the number of stored elements should be
expired.
|
int |
getMinimumExpiryAge() |
float |
getMinimumShrinkSizeRatio() |
void |
performExpiry(CacheIteratorFactory iteratorFactory,
TrackableCache cache,
boolean hasLRUOrdering,
ExpiryStrategy.ExpiryPressure expiryPressure)
Performs an expiry according to the LRU principle.
|
void |
setExpiryObjectCountRatio(float expiryObjectCountRatio)
Sets the minimum ratio of elements that should be expired (dependent on the element count).
|
void |
setMinimumExpiryAge(int minimumExpiryAge)
Set the minimum age (in ms) of objects to be purged from the cache.
|
void |
setMinimumShrinkSizeRatio(float minimumShrinkSizeRatio)
This is the minimal percentage of the maximum cache size (in bytes) to whiSequencedHashMap
ch the cache will
shrink.
|
public void performExpiry(CacheIteratorFactory iteratorFactory, TrackableCache cache, boolean hasLRUOrdering, ExpiryStrategy.ExpiryPressure expiryPressure)
Performs an expiry according to the LRU principle. Elements younger than the
minimumExpiryAge
won't be expired.
The three factors that count in case of the expiry are:
minimumshrinkSizeRatio
expiryObjectCountRatio
and
maximumElementCount
performExpiry
in interface ExpiryStrategy
iteratorFactory
- A CacheIteratorFactory
that creates an Iterator
to the caches
entries. The Iterator
created using the CacheIteratorFactory
shall be used
to removed entries from the cache.cache
- the TrackableCache
the ExpiryStrategy
is assigned tohasLRUOrdering
- If this is true, the collection has an LRU ordering, implying that it
will iterate from the oldest to the newest entry.expiryPressure
- Indicates if the expiry call is urgent or not.public int getMinimumExpiryAge()
public void setMinimumExpiryAge(int minimumExpiryAge)
minimumExpiryAge
- The minimum time an element is held in the cache. Must be greater then
or equal to zero.IllegalArgumentException
- Once the age was below 0.public float getExpiryObjectCountRatio()
So 0.1 indicates that 10% of all elements should be evicted.
public void setExpiryObjectCountRatio(float expiryObjectCountRatio)
Example: 0.1 means 10% of the elements should be evicted.
expiryObjectCountRatio
- The ratio between 0 and 1 (0% - 100%)IllegalArgumentException
- Once the ratio was out of the interval.public float getMinimumShrinkSizeRatio()
setMinimumShrinkSizeRatio(float)
public void setMinimumShrinkSizeRatio(float minimumShrinkSizeRatio)
Example: 0.8 indicates that that cache size will shrink to round about 80% of its size.
minimumShrinkSizeRatio
- A factor greater zero and lower 1.IllegalArgumentException
- Once the ratio was out of the interval.Copyright © 2024 levigo holding gmbh. All rights reserved.