use std::{
num::NonZeroU64,
path::{Path, PathBuf},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum LakehouseByteCacheFill {
#[default]
Disabled,
ReadThrough,
FillBeforeRead,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LakehouseByteCache {
root: PathBuf,
serves_hits: bool,
fill: LakehouseByteCacheFill,
max_retained_bytes: Option<NonZeroU64>,
}
impl LakehouseByteCache {
pub fn new(root: impl Into<PathBuf>) -> Self {
Self { root: root.into(), serves_hits: true, fill: LakehouseByteCacheFill::Disabled, max_retained_bytes: None }
}
pub fn with_fill(mut self, fill: LakehouseByteCacheFill) -> Self {
self.fill = fill;
self
}
pub fn ignoring_hits(mut self) -> Self {
self.serves_hits = false;
self
}
pub fn with_max_retained_bytes(mut self, bytes: NonZeroU64) -> Self {
self.max_retained_bytes = Some(bytes);
self
}
pub(crate) fn root(&self) -> &Path {
&self.root
}
pub(crate) fn serves_hits(&self) -> bool {
self.serves_hits
}
pub(crate) fn fill(&self) -> LakehouseByteCacheFill {
self.fill
}
pub(crate) fn max_retained_bytes(&self) -> Option<NonZeroU64> {
self.max_retained_bytes
}
}