use crate::Result;
use std::path;
#[derive(Debug, Clone)]
pub struct CacheBuilder {
opts: super::Options,
}
impl CacheBuilder {
pub fn new<P: AsRef<path::Path>>(path: P) -> Self {
let opts = super::Options {
path: path.as_ref().to_owned(),
dir_depth: 2,
track_access: false,
lru_size: 0,
rbuff_sz: 8192,
wbuff_sz: 8192,
};
CacheBuilder { opts }
}
pub fn dir_depth(mut self, depth: u8) -> Self {
self.opts.dir_depth = depth;
self
}
pub fn memory_lru_max_size(mut self, size: usize) -> Self {
self.opts.lru_size = size;
self
}
pub fn read_write_buffer(mut self, size: usize) -> Self {
self.opts.rbuff_sz = size;
self.opts.wbuff_sz = size;
self
}
pub fn track_access(mut self, toggle: bool) -> Self {
self.opts.track_access = toggle;
self
}
pub async fn build(self) -> Result<super::Cache> {
super::Cache::create(self.opts).await
}
}
impl Default for CacheBuilder {
fn default() -> Self {
const DIR: &str = "./cache";
Self::new(DIR)
}
}