public interface ExpirationAfterWriteStrategy
| Modifier and Type | Method and Description |
|---|---|
static ExpirationAfterWriteStrategy |
basedOnTimeForRefillingBucketUpToMax(Duration keepAfterRefillDuration)
Returns strategy that smartly calculates TTL based of current bucket state,
buckets are not persisted in storage longer than time required to refill all consumed tokens plus keepAfterRefillDuration
|
long |
calculateTimeToLiveMillis(RemoteBucketState state,
long currentTimeNanos)
Calculates the time to live for bucket that is going to be persisted to the remote storage
|
static ExpirationAfterWriteStrategy |
fixedTimeToLive(Duration ttl)
Returns strategy that makes to store buckets with fixed TTL.
|
static ExpirationAfterWriteStrategy |
none()
Returns strategy that makes to store buckets forever.
|
long calculateTimeToLiveMillis(RemoteBucketState state, long currentTimeNanos)
state - the state of bucket that is going to be persisted to the remote storagecurrentTimeNanos - the time of operationstatic ExpirationAfterWriteStrategy none()
Do not use this strategy in use-case of many buckets in order to avoid storage overflowing by unused buckets.
fixedTimeToLive(Duration),
basedOnTimeForRefillingBucketUpToMax(Duration)static ExpirationAfterWriteStrategy fixedTimeToLive(Duration ttl)
This strategy can lead to overconsumption if provided ttl is less significantly than refill period,
because information about previously consumed in such misconfiguration case can be lost in remote storage faster than it should be.
As well as consumed capacity to store all buckets in storage can be significantly more than it can be in case of TTL is significantly greater than refill period of bucket.
So consider to use basedOnTimeForRefillingBucketUpToMax(Duration) for more precise TTL calculation based on current bucket state.
ttl - fixed TTL that will be used for storing the bucketsbasedOnTimeForRefillingBucketUpToMax(Duration)static ExpirationAfterWriteStrategy basedOnTimeForRefillingBucketUpToMax(Duration keepAfterRefillDuration)
keepAfterRefillDuration - specifies how long bucket should be held in the cache after all consumed tokens have been refilled.
It can be a zero duration, but from performance considerations it is recommended to provide at least few seconds,
because reusing of already persisted can be faster that initialization of bucket from scratch,
so keepAfterRefillDuration helps to not evict buckets from storage too frequent.basedOnTimeForRefillingBucketUpToMax(Duration)Copyright © 2022. All rights reserved.