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 interop_get<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>, CachekitError>
pub async fn interop_get<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, CachekitError>
Retrieve and deserialize an interop-mode value stored under key.
Identical to Self::get except the payload is decoded with
crate::interop::deserialize, which consumes exactly one MessagePack
document and rejects trailing bytes (interop/v1 spec MUST). A
Python-SDK-internal CK frame is rejected with a specific diagnostic
instead of silently decoding as the integer 67.
Use with keys from crate::interop::interop_key on a client
without a namespace prefix. There is no interop-specific write
method: Self::set already writes plain MessagePack (no ByteStorage
envelope), which is the interop value format.
§Errors
Returns CachekitError::Config if the client was built with
CacheKitBuilder::namespace (or CACHEKIT_NAMESPACE): the prefix
would rewrite the storage key to {prefix}:{interop_key}, which no
other SDK computes — every cross-SDK entry would silently miss. Interop
keys carry their own namespace segment; failing loudly here beats a
100% miss rate that looks like a cold cache.
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.
Source§impl CacheKit
impl CacheKit
Sourcepub fn io(api_key: &str) -> Result<CacheKitBuilder, CachekitError>
pub fn io(api_key: &str) -> Result<CacheKitBuilder, CachekitError>
CachekitIO — managed SaaS cache, zero infrastructure.
- Backend: cachekit.io HTTP API
- L1 cache: on (1 000 entries)
- Encryption: no (add via
.encryption()) - Default TTL: 3 600 s
Good for: serverless, edge compute, managed caching without Redis.
§Errors
Returns CachekitError if api_key is empty.
§Example
let cache = cachekit::CacheKit::io("ck_live_abc123")?
.namespace("edge")
.build()?;