pub struct CacheEntryBuilder<T> { /* private fields */ }
Expand description
The builder for building CacheEntry with supplied parameters.
Implementations§
Source§impl<T> CacheEntryBuilder<T>
impl<T> CacheEntryBuilder<T>
Sourcepub fn new<F>(f: F) -> CacheEntryBuilder<T>where
F: FnOnce() -> T,
pub fn new<F>(f: F) -> CacheEntryBuilder<T>where
F: FnOnce() -> T,
Return a new CacheEntryBuilder.
This method takes a closure which should return the value to be cached.
Sourcepub fn with_delta<F>(self, f: F) -> CacheEntryBuilder<T>
pub fn with_delta<F>(self, f: F) -> CacheEntryBuilder<T>
Set the delta.
Usually the delta value is mesured from the time took by the recomputation function. However, if the recomputation function does not reflect the actual time required (for example, a asynchronous computation), then the delta value can be set via this method.
The reference of the value returned by the recomputation function is passed to the closure.
Sourcepub fn with_ttl<F>(self, f: F) -> CacheEntryBuilder<T>
pub fn with_ttl<F>(self, f: F) -> CacheEntryBuilder<T>
Set the ttl.
The reference of the value returned by the recomputation function is passed to the closure.
If the ttl is not set then the cache entry will become a eternal cache entry that will never expire.
Sourcepub fn with_beta(self, beta: f32) -> CacheEntryBuilder<T>
pub fn with_beta(self, beta: f32) -> CacheEntryBuilder<T>
Set the beta value.
Beta value > 1.0
favors more eager early expiration, value < 1.0
favors lazier early expiration.
The default value 1.0
is usually the optimal value for most use cases.
Sourcepub fn build(self) -> CacheEntry<T>
pub fn build(self) -> CacheEntry<T>
Return a new CacheEntry with the supplied parameters.