pub struct DiskCache { /* private fields */ }
Expand description
L2 Disk cache implementation
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub async fn new(config: DiskCacheConfig) -> Result<Self>
pub async fn new(config: DiskCacheConfig) -> Result<Self>
Create a new disk cache
§Errors
Returns an error if the database connection fails or if the cache cannot be initialized
Sourcepub fn store<T>(&self, key: &str, data: &T, cache_type: &str) -> Result<()>where
T: Serialize,
pub fn store<T>(&self, key: &str, data: &T, cache_type: &str) -> Result<()>where
T: Serialize,
Store data in the disk cache
§Errors
This function will return an error if:
- Serialization fails
- Compression fails (if enabled)
- Database operations fail
- File I/O operations fail
Sourcepub async fn get<T>(&self, key: &str) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
pub async fn get<T>(&self, key: &str) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
Retrieve data from the disk cache
§Errors
This function will return an error if:
- Database operations fail
- Deserialization fails
- Decompression fails (if data was compressed)
Sourcepub fn remove(&self, key: &str) -> Result<bool>
pub fn remove(&self, key: &str) -> Result<bool>
Remove an entry from the disk cache
§Errors
This function will return an error if database operations fail
Sourcepub fn clear(&self) -> Result<()>
pub fn clear(&self) -> Result<()>
Clear all entries from the disk cache
§Errors
This function will return an error if database operations fail
Sourcepub fn clear_by_type(&self, cache_type: &str) -> Result<()>
pub fn clear_by_type(&self, cache_type: &str) -> Result<()>
Sourcepub async fn get_stats(&self) -> DiskCacheStats
pub async fn get_stats(&self) -> DiskCacheStats
Get cache statistics
Sourcepub fn get_utilization(&self) -> Result<f64>
pub fn get_utilization(&self) -> Result<f64>
Get cache utilization percentage
§Errors
This function will return an error if database operations fail
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 !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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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