pub struct CacheWrapper { /* private fields */ }Expand description
What: Combined cache wrapper that uses memory and optionally disk cache.
Inputs: None (created via CacheWrapper::new())
Output:
CacheWrapperinstance ready for use
Details:
- Always uses in-memory LRU cache
- Optionally uses disk cache if enabled in config
- Checks memory cache first, then disk cache
- Writes to both caches when storing
Implementations§
Source§impl CacheWrapper
impl CacheWrapper
Sourcepub fn new(config: &CacheConfig) -> Result<Self, CacheError>
pub fn new(config: &CacheConfig) -> Result<Self, CacheError>
What: Create a new cache wrapper with memory and optional disk cache.
Inputs:
config: Cache configuration
Output:
Result<CacheWrapper>with configured caches, or error if initialization fails
Details:
- Always creates memory cache
- Creates disk cache if enabled in config
- Returns error if disk cache creation fails
§Errors
- Returns
Err(CacheError::Io)if disk cache directory creation fails
Sourcepub fn get<V>(&self, key: &str) -> Option<V>
pub fn get<V>(&self, key: &str) -> Option<V>
What: Get a value from cache (checks memory first, then disk).
Inputs:
key: Cache key
Output:
Option<V>containing cached value if found,Noneotherwise
Details:
- Checks memory cache first (fastest)
- Falls back to disk cache if memory miss
- Promotes disk cache hits to memory cache
Sourcepub fn set<V>(
&self,
key: &str,
value: &V,
ttl: Duration,
) -> Result<(), CacheError>
pub fn set<V>( &self, key: &str, value: &V, ttl: Duration, ) -> Result<(), CacheError>
What: Store a value in cache (writes to both memory and disk if enabled).
Inputs:
key: Cache keyvalue: Value to cachettl: Time-to-live duration
Output:
Result<(), CacheError>indicating success or failure
Details:
- Writes to memory cache (always)
- Writes to disk cache if enabled
- Errors in disk cache don’t prevent memory cache write
§Errors
- Returns
Err(CacheError::Serialization)if value serialization fails
Sourcepub fn invalidate(&self, key: &str) -> Result<(), CacheError>
pub fn invalidate(&self, key: &str) -> Result<(), CacheError>
What: Invalidate a cache entry (removes from both memory and disk).
Inputs:
key: Cache key to invalidate
Output:
Result<(), CacheError>indicating success or failure
Details:
- Removes from memory cache
- Removes from disk cache if enabled
§Errors
- Returns
Err(CacheError::Io)if disk cache file removal fails (disk cache only)
Sourcepub fn clear(&self) -> Result<(), CacheError>
pub fn clear(&self) -> Result<(), CacheError>
What: Clear all cache entries (both memory and disk).
Inputs: None
Output:
Result<(), CacheError>indicating success or failure
Details:
- Clears memory cache
- Clears disk cache if enabled
§Errors
- Returns
Err(CacheError::Io)if disk cache cleanup fails (disk cache only)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CacheWrapper
impl RefUnwindSafe for CacheWrapper
impl Send for CacheWrapper
impl Sync for CacheWrapper
impl Unpin for CacheWrapper
impl UnwindSafe for CacheWrapper
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