pub struct TTLConfig {
pub base_ttl: Duration,
pub min_ttl: Duration,
pub max_ttl: Duration,
pub hot_threshold: u64,
pub cold_threshold: u64,
pub adaptation_rate: f64,
pub enable_background_cleanup: bool,
pub cleanup_interval: Duration,
pub max_entries: usize,
pub memory_pressure_threshold: f64,
pub enable_adaptive_ttl: bool,
pub access_window_secs: u64,
}Expand description
Configuration for adaptive TTL cache
Fields§
§base_ttl: DurationBase TTL for new entries
min_ttl: DurationMinimum TTL (entries won’t be reduced below this)
max_ttl: DurationMaximum TTL (entries won’t be extended beyond this)
hot_threshold: u64Hot threshold - access count above which TTL is extended
cold_threshold: u64Cold threshold - access count below which TTL is reduced
adaptation_rate: f64Adaptation rate - how fast TTL changes (0.0 - 1.0)
enable_background_cleanup: boolEnable background cleanup task
cleanup_interval: DurationCleanup interval for expired entries
max_entries: usizeMaximum number of entries in cache
memory_pressure_threshold: f64Memory pressure threshold (0.0 - 1.0)
enable_adaptive_ttl: boolEnable adaptive TTL based on access patterns
access_window_secs: u64Time window for access pattern analysis (seconds)
Implementations§
Source§impl TTLConfig
impl TTLConfig
Sourcepub fn high_hit_rate() -> Self
pub fn high_hit_rate() -> Self
Create a configuration optimized for high-hit-rate scenarios
Sourcepub fn memory_constrained() -> Self
pub fn memory_constrained() -> Self
Create a configuration optimized for memory-constrained environments
Sourcepub fn write_heavy() -> Self
pub fn write_heavy() -> Self
Create a configuration optimized for write-heavy workloads
Sourcepub fn validate(&self) -> Result<(), TTLConfigError>
pub fn validate(&self) -> Result<(), TTLConfigError>
Validate the configuration
Sourcepub fn calculate_ttl(
&self,
current_ttl: Duration,
access_count: u64,
) -> Duration
pub fn calculate_ttl( &self, current_ttl: Duration, access_count: u64, ) -> Duration
Calculate adapted TTL based on access count
Sourcepub fn with_base_ttl(self, ttl: Duration) -> Self
pub fn with_base_ttl(self, ttl: Duration) -> Self
Builder method to set base TTL
Sourcepub fn with_min_ttl(self, ttl: Duration) -> Self
pub fn with_min_ttl(self, ttl: Duration) -> Self
Builder method to set min TTL
Sourcepub fn with_max_ttl(self, ttl: Duration) -> Self
pub fn with_max_ttl(self, ttl: Duration) -> Self
Builder method to set max TTL
Sourcepub fn with_hot_threshold(self, threshold: u64) -> Self
pub fn with_hot_threshold(self, threshold: u64) -> Self
Builder method to set hot threshold
Sourcepub fn with_cold_threshold(self, threshold: u64) -> Self
pub fn with_cold_threshold(self, threshold: u64) -> Self
Builder method to set cold threshold
Sourcepub fn with_adaptation_rate(self, rate: f64) -> Self
pub fn with_adaptation_rate(self, rate: f64) -> Self
Builder method to set adaptation rate
Sourcepub fn with_max_entries(self, max: usize) -> Self
pub fn with_max_entries(self, max: usize) -> Self
Builder method to set max entries
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TTLConfig
impl RefUnwindSafe for TTLConfig
impl Send for TTLConfig
impl Sync for TTLConfig
impl Unpin for TTLConfig
impl UnsafeUnpin for TTLConfig
impl UnwindSafe for TTLConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.