pub struct SharedCacheConfigBuilder<Req, K, Resp> { /* private fields */ }Expand description
Builder for configuring and constructing a shared cache layer.
Implementations§
Sourcepub fn max_size(self, size: usize) -> Self
pub fn max_size(self, size: usize) -> Self
Sets the maximum number of entries in the cache.
Default: 100
Sourcepub fn ttl(self, ttl: Duration) -> Self
pub fn ttl(self, ttl: Duration) -> Self
Sets the time-to-live for cached entries.
If set, entries will expire after the specified duration. Default: None (no expiration)
Sourcepub fn eviction_policy(self, policy: EvictionPolicy) -> Self
pub fn eviction_policy(self, policy: EvictionPolicy) -> Self
Sets the eviction policy for the cache.
Determines which entry to evict when the cache reaches capacity.
§Options
EvictionPolicy::Lru- Least Recently Used (default)EvictionPolicy::Lfu- Least Frequently UsedEvictionPolicy::Fifo- First In, First Out
Default: EvictionPolicy::Lru
Sourcepub fn key_extractor<F>(self, f: F) -> Self
pub fn key_extractor<F>(self, f: F) -> Self
Sets the function that extracts a cache key from a request.
This function must be provided before building.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Sets the name of this cache instance for observability.
Default: "<unnamed>"
Sourcepub fn on_eviction<F>(self, f: F) -> Self
pub fn on_eviction<F>(self, f: F) -> Self
Registers a callback when an entry is evicted from the cache.
Sourcepub fn build(self) -> Result<SharedCacheLayer<Req, K, Resp>, CacheBuildError>
pub fn build(self) -> Result<SharedCacheLayer<Req, K, Resp>, CacheBuildError>
Builds the shared cache layer.
§Errors
Returns crate::CacheBuildError::MissingKeyExtractor if key_extractor
was not set before calling build().