pub trait CacheStore:
Send
+ Sync
+ 'static {
// Required methods
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn set<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
value: &'life3 [u8],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait;
fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn clear<'life0, 'life1, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided method
fn entry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
_namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Expand description
Backend trait for pluggable cache storage.
Keys and values are opaque strings / bytes — the typed cache wrapper in
whatsapp-rust handles serialization via serde.
§Namespaces
Each logical cache uses a unique namespace string (e.g., "group",
"device", "lid_pn_by_lid"). Implementations should use this to
partition keys — for example, a Redis implementation might prefix keys
as {namespace}:{key}.
§Error handling
Cache operations are best-effort. The client falls back gracefully when cache reads fail (treats as miss) and logs warnings on write failures. Implementations should still return errors for observability.
Required Methods§
Sourcefn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Retrieve a cached value by namespace and key.
Sourcefn set<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
value: &'life3 [u8],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn set<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
value: &'life3 [u8],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Store a value with an optional TTL.
When ttl is None, the entry should persist until explicitly deleted
or evicted by the implementation’s own policy.
Sourcefn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Delete a single key from the given namespace.
Provided Methods§
Sourcefn entry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
_namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn entry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
_namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Return the approximate number of entries in a namespace.
Used only for diagnostics. Implementations that cannot cheaply
report counts should return Ok(0).