pub struct FusionCacheBuilder<TKey: Hash + Eq + Send + Sync + Clone + Serialize + DeserializeOwned + 'static, TValue: Clone + Send + Sync + Serialize + DeserializeOwned + 'static> { /* private fields */ }
Implementations§
Source§impl<TKey: Hash + Eq + Send + Sync + Clone + Serialize + DeserializeOwned + Debug + 'static, TValue: Clone + Send + Sync + Serialize + DeserializeOwned + Debug + 'static> FusionCacheBuilder<TKey, TValue>
impl<TKey: Hash + Eq + Send + Sync + Clone + Serialize + DeserializeOwned + Debug + 'static, TValue: Clone + Send + Sync + Serialize + DeserializeOwned + Debug + 'static> FusionCacheBuilder<TKey, TValue>
pub fn new() -> Self
Sourcepub fn with_capacity(self, capacity: u64) -> Self
pub fn with_capacity(self, capacity: u64) -> Self
Sets the maximum capacity of the cache. This is the maximum number of entries the cache can hold before it starts evicting old entries. The default capacity is 1000 entries.
§Arguments
capacity
- The maximum number of entries the cache can hold
Sourcepub fn with_time_to_live(self, time_to_live: Duration) -> Self
pub fn with_time_to_live(self, time_to_live: Duration) -> Self
Sets the time-to-live for entries in the cache.
§Arguments
time_to_live
- The time-to-live for entries in the cache
Sourcepub fn with_time_to_idle(self, time_to_idle: Duration) -> Self
pub fn with_time_to_idle(self, time_to_idle: Duration) -> Self
Sets the time-to-idle for entries in the cache.
§Arguments
time_to_idle
- The time-to-idle for entries in the cache
Sourcepub fn with_fail_safe(
self,
entry_ttl: Duration,
failsafe_cycle_ttl: Duration,
max_cycles: Option<u64>,
soft_timeout: Option<Duration>,
) -> Self
pub fn with_fail_safe( self, entry_ttl: Duration, failsafe_cycle_ttl: Duration, max_cycles: Option<u64>, soft_timeout: Option<Duration>, ) -> Self
Configures the fail-safe mechanism for the cache. This allows the cache to handle situations where the factory is slow or fails to respond.
§Arguments
entry_ttl
- The time-to-live for entries in the fail-safe cachefailsafe_cycle_ttl
- The time-to-live for a fail-safe cyclemax_cycles
- The maximum number of cycles the fail-safe cache can go through before giving upsoft_timeout
- An optional soft timeout for factory operations, after which the cache will try to use the fail-safe cache
Sourcepub fn with_hard_timeout(self, timeout: Duration) -> Self
pub fn with_hard_timeout(self, timeout: Duration) -> Self
Sets a hard timeout for factory operations.
If the factory does not return a value within this duration, it will return a FusionCacheError::FactoryTimeout
.
§Arguments
timeout
- The maximum duration to wait for the factory to return a value
Sourcepub fn set_factory_background_execution(
self,
should_execute_in_background: bool,
) -> Self
pub fn set_factory_background_execution( self, should_execute_in_background: bool, ) -> Self
Configures whether the factory should execute in the background after a soft timeout.
If set to true
, the factory will continue to run in the background even after a soft timeout.
§Arguments
should_execute_in_background
- Whether the factory should execute in the background
Sourcepub fn with_redis(
self,
address: String,
application_name: String,
should_writes_happen_in_background: bool,
entry_ttl: Option<Duration>,
) -> Self
pub fn with_redis( self, address: String, application_name: String, should_writes_happen_in_background: bool, entry_ttl: Option<Duration>, ) -> Self
Configures Redis as a level 2 cache.
If use_as_distributed_cache
is true, it will also be used as a distributed cache, that is, Redis will also be used as a backplane for the cache.
§Arguments
address
- The address of the Redis server.application_name
- The name of the application.should_writes_happen_in_background
- Whether the writes to Redis should happen in the background.entry_ttl
- The time-to-live for entries in the Redis cache.