pub struct DiskCache { /* private fields */ }Expand description
Local disk cache with LRU eviction.
Stores copies of remote objects under cache_dir using the object’s
path as the filename (slashes replaced with __). When the cache
exceeds max_size_bytes, the least-recently accessed entries are
evicted until the cache fits within budget.
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub async fn new(config: CacheConfig) -> Result<Self>
pub async fn new(config: CacheConfig) -> Result<Self>
Create a new disk cache.
The cache directory is created if it does not already exist.
§Errors
Returns ObjStoreError::CacheIo if the cache directory cannot be
created or scanned.
Sourcepub async fn get(&self, key: &str) -> Option<Vec<u8>>
pub async fn get(&self, key: &str) -> Option<Vec<u8>>
Get a cached object by key, returning the bytes if present.
Updates the access time for LRU tracking. Returns None on miss.
Sourcepub async fn put(&self, key: &str, data: &[u8]) -> Result<()>
pub async fn put(&self, key: &str, data: &[u8]) -> Result<()>
Store an object in the cache.
Evicts LRU entries if necessary to fit within the size budget.
§Errors
Returns ObjStoreError::CacheIo on filesystem write failures.
Sourcepub async fn remove(&self, key: &str) -> Result<()>
pub async fn remove(&self, key: &str) -> Result<()>
Remove an object from the cache.
§Errors
Returns ObjStoreError::CacheIo on filesystem delete failures.
Sourcepub fn contains(&self, key: &str) -> bool
pub fn contains(&self, key: &str) -> bool
Check if a key is in the cache without updating access time.
Sourcepub fn current_size(&self) -> u64
pub fn current_size(&self) -> u64
Current total size of cached data.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Number of entries in the cache.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DiskCache
impl !RefUnwindSafe for DiskCache
impl Send for DiskCache
impl Sync for DiskCache
impl Unpin for DiskCache
impl UnsafeUnpin for DiskCache
impl UnwindSafe for DiskCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more