pub struct CacheKit { /* private fields */ }Expand description
Production-ready cache client with optional L1 in-process cache layer.
Implementations§
Source§impl CacheKit
impl CacheKit
Sourcepub fn builder() -> CacheKitBuilder
pub fn builder() -> CacheKitBuilder
Create a new builder.
Sourcepub fn from_env() -> Result<CacheKitBuilder, CachekitError>
pub fn from_env() -> Result<CacheKitBuilder, CachekitError>
Build from environment variables via crate::config::CachekitConfig::from_env.
Creates a crate::backend::cachekitio::CachekitIO backend from the
config. Requires the cachekitio feature.
Sourcepub async fn get<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>, CachekitError>
pub async fn get<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, CachekitError>
Retrieve and deserialize a value stored under key.
Returns None if the key does not exist.
Checks L1 cache before hitting the backend.
Sourcepub async fn set<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<(), CachekitError>
pub async fn set<T: Serialize>( &self, key: &str, value: &T, ) -> Result<(), CachekitError>
Serialize and store value under key using the client’s default TTL.
Sourcepub async fn set_with_ttl<T: Serialize>(
&self,
key: &str,
value: &T,
ttl: Duration,
) -> Result<(), CachekitError>
pub async fn set_with_ttl<T: Serialize>( &self, key: &str, value: &T, ttl: Duration, ) -> Result<(), CachekitError>
Serialize and store value under key with an explicit ttl.
Returns CachekitError::Config if ttl is less than 1 second.
Sourcepub async fn delete(&self, key: &str) -> Result<bool, CachekitError>
pub async fn delete(&self, key: &str) -> Result<bool, CachekitError>
Delete key and return true if it existed.
Invalidates the L1 entry regardless of the backend result.
Sourcepub async fn exists(&self, key: &str) -> Result<bool, CachekitError>
pub async fn exists(&self, key: &str) -> Result<bool, CachekitError>
Return true if key exists without fetching the value.
Sourcepub fn secure(&self) -> Result<SecureCache<'_>, CachekitError>
pub fn secure(&self) -> Result<SecureCache<'_>, CachekitError>
Return a SecureCache handle that encrypts all values before storage.
L1 stores ciphertext (not plaintext) to preserve the zero-knowledge property across all cache layers.
§Errors
Returns CachekitError::Config if no encryption layer is configured.
Configure encryption via CacheKitBuilder::encryption or
CacheKitBuilder::encryption_from_bytes.