pub struct CacheConfig {
pub max_capacity: usize,
pub default_ttl: Option<Duration>,
pub cleanup_interval: Duration,
pub eviction_batch_size: usize,
pub enable_stats: bool,
}Expand description
缓存配置
Fields§
§max_capacity: usize最大容量(条目数,默认 1000)
default_ttl: Option<Duration>默认 TTL(None 表示永不过期,默认 5 分钟)
cleanup_interval: Duration过期检查间隔(默认 1 分钟)
eviction_batch_size: usize批量淘汰数量(默认 10%)
enable_stats: bool是否启用统计(默认 true)
Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn max_capacity(self, capacity: usize) -> Self
pub fn max_capacity(self, capacity: usize) -> Self
设置最大容量
Sourcepub fn default_ttl(self, ttl: Duration) -> Self
pub fn default_ttl(self, ttl: Duration) -> Self
设置默认 TTL
Sourcepub fn cleanup_interval(self, interval: Duration) -> Self
pub fn cleanup_interval(self, interval: Duration) -> Self
设置过期检查间隔
Sourcepub fn eviction_batch_size(self, size: usize) -> Self
pub fn eviction_batch_size(self, size: usize) -> Self
设置批量淘汰数量
Sourcepub fn high_performance() -> Self
pub fn high_performance() -> Self
创建高性能配置(大容量、长 TTL、禁用统计)
Sourcepub fn short_lived() -> Self
pub fn short_lived() -> Self
创建短期缓存配置(小容量、极短 TTL)
Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§fn clone(&self) -> CacheConfig
fn clone(&self) -> CacheConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheConfig
impl Debug for CacheConfig
Auto Trait Implementations§
impl Freeze for CacheConfig
impl RefUnwindSafe for CacheConfig
impl Send for CacheConfig
impl Sync for CacheConfig
impl Unpin for CacheConfig
impl UnwindSafe for CacheConfig
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
Mutably borrows from an owned value. Read more