use crate::CacheActor;
use actix::{Actor, Addr};
use hitbox::settings::{CacheSettings, Status};
use hitbox_backend::Backend;
use std::marker::PhantomData;
pub struct CacheBuilder<B>
where
B: Backend + Actor,
{
settings: CacheSettings,
_p: PhantomData<B>,
}
impl<B> Default for CacheBuilder<B>
where
B: Backend,
{
fn default() -> Self {
CacheBuilder {
settings: CacheSettings {
cache: Status::Enabled,
stale: Status::Enabled,
lock: Status::Disabled,
},
_p: PhantomData::default(),
}
}
}
impl<B> CacheBuilder<B>
where
B: Backend,
{
pub fn enable(mut self) -> Self {
self.settings.cache = Status::Enabled;
self
}
pub fn disable(mut self) -> Self {
self.settings.cache = Status::Disabled;
self
}
pub fn with_stale(mut self) -> Self {
self.settings.stale = Status::Enabled;
self
}
pub fn without_stale(mut self) -> Self {
self.settings.stale = Status::Disabled;
self
}
pub fn with_lock(mut self) -> Self {
self.settings.lock = Status::Enabled;
self
}
pub fn without_lock(mut self) -> Self {
self.settings.lock = Status::Disabled;
self
}
pub fn finish(self, backend: Addr<B>) -> CacheActor<B> {
CacheActor {
settings: self.settings,
backend,
}
}
}