pub struct ApiCache { /* private fields */ }Expand description
Cache for API responses backed by a local SQLite database.
This is the public facade for the cache-internals seam tracked as
cpf-0005 in
policy/clippy-protected-fields.toml.
External callers must use the public methods on this type; adding a
raw_connection (or similar) accessor would re-introduce the failure
mode the seam guards against (custom SQL queries silently breaking on
a future schema migration).
The protected raw fields live on the private ApiCacheInner
struct that this type wraps. The split exists so that
clippy::disallowed_fields can target the public paths
(ApiCache::*) when the lint activates in a follow-up PR, while
internal methods continue to access their working state via the
private inner type without tripping the lint.
Implementations§
Source§impl ApiCache
impl ApiCache
Sourcepub fn open_read_only(path: impl AsRef<Path>) -> Result<Self>
pub fn open_read_only(path: impl AsRef<Path>) -> Result<Self>
Open an existing cache in read-only mode without initializing schema.
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 lookup<T: DeserializeOwned>(&self, key: &str) -> Result<CacheLookup<T>>
pub fn lookup<T: DeserializeOwned>(&self, key: &str) -> Result<CacheLookup<T>>
Look up a cached value and distinguish fresh hit, stale hit, and miss.
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 count_older_than(&self, cutoff: DateTime<Utc>) -> Result<usize>
pub fn count_older_than(&self, cutoff: DateTime<Utc>) -> Result<usize>
Count entries cached before the given cutoff.
Sourcepub fn cleanup_older_than(&self, cutoff: DateTime<Utc>) -> Result<usize>
pub fn cleanup_older_than(&self, cutoff: DateTime<Utc>) -> Result<usize>
Remove entries cached before the given cutoff.
Sourcepub fn stats(&self) -> Result<CacheStats>
pub fn stats(&self) -> Result<CacheStats>
Get cache statistics.
Sourcepub fn inspect(&self) -> Result<CacheInspection>
pub fn inspect(&self) -> Result<CacheInspection>
Inspect cache statistics and entry timestamp bounds.