pub struct ApiCache { /* private fields */ }Expand description
Cache for API responses backed by a local SQLite database.
Implementations§
Source§impl ApiCache
impl ApiCache
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create an in-memory cache (for testing).
Sourcepub fn with_max_size(self, max_size_bytes: u64) -> Self
pub fn with_max_size(self, max_size_bytes: u64) -> Self
Create a cache with a maximum size limit.
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
Get a cached value if it exists and hasn’t expired.
Sourcepub fn set<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
pub fn set<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
Store a value in the cache.
Sourcepub fn set_with_ttl<T: Serialize>(
&self,
key: &str,
value: &T,
ttl: Duration,
) -> Result<()>
pub fn set_with_ttl<T: Serialize>( &self, key: &str, value: &T, ttl: Duration, ) -> Result<()>
Store a value with a custom TTL.
Sourcepub fn cleanup_expired(&self) -> Result<usize>
pub fn cleanup_expired(&self) -> Result<usize>
Remove expired entries from the cache.
Sourcepub fn stats(&self) -> Result<CacheStats>
pub fn stats(&self) -> Result<CacheStats>
Get cache statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ApiCache
impl !RefUnwindSafe for ApiCache
impl Send for ApiCache
impl !Sync for ApiCache
impl Unpin for ApiCache
impl UnsafeUnpin for ApiCache
impl !UnwindSafe for ApiCache
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