pub struct CacheBuilder<B>{ /* private fields */ }Expand description
Cache actor configurator.
§Example
use actix::prelude::*;
use hitbox_actix::{Cache, RedisBackend, CacheError};
#[actix_rt::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let backend = RedisBackend::new()
.await?
.start();
let cache = Cache::builder()
.enable()
.finish(backend)
.start();
Ok(())
}Implementations§
Source§impl<B> CacheBuilder<B>where
B: Backend,
impl<B> CacheBuilder<B>where
B: Backend,
Sourcepub fn disable(self) -> Self
pub fn disable(self) -> Self
Disable interaction with cache backend.
All messages sent to disabled Cache actor passed directly to an upstream actor.
Sourcepub fn with_stale(self) -> Self
pub fn with_stale(self) -> Self
Enable stale cache mechanics. (Default value).
If CacheActor receives a stale value, it does not return it immediately. It polls data from upstream, and if the upstream returned an error, the CacheActor returns a stale value. If no error occurred in the upstream, then a fresh value is stored in the cache and returned.
Sourcepub fn without_stale(self) -> Self
pub fn without_stale(self) -> Self
Disable stale cache mechanics.
Sourcepub fn with_lock(self) -> Self
pub fn with_lock(self) -> Self
Enable cache lock mechanics.
Prevents multiple upstream requests for the same cache key in case of cache data is missing.
Only the first request will produce an upstream request.
The remaining requests wait for a first upstream response and return updated data.
If with_stale is enabled the remaining requests don’t wait for an upstream response
and return stale cache data if it exists.
Sourcepub fn without_lock(self) -> Self
pub fn without_lock(self) -> Self
Disable cache lock mechanics. (Default value).