Skip to main content

crabkey_types/
cache.rs

1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4#[allow(dead_code)]
5pub struct CacheEntry {
6    pub value: Vec<u8>,
7    pub ttl: Option<Duration>,
8}
9
10#[derive(Debug, thiserror::Error)]
11#[allow(dead_code)]
12pub enum CacheError {
13    #[error("cache miss")]
14    Miss,
15    #[error("serialization error: {0}")]
16    Serialize(String),
17    #[error("backend error: {0}")]
18    Backend(String),
19}
20
21#[async_trait::async_trait]
22#[allow(dead_code)]
23pub trait CacheStore: Send + Sync + 'static {
24    async fn get(&self, key: &str) -> Result<CacheEntry, CacheError>;
25    async fn set(&self, key: &str, entry: CacheEntry) -> Result<(), CacheError>;
26    async fn delete(&self, key: &str) -> Result<(), CacheError>;
27    async fn exists(&self, key: &str) -> Result<bool, CacheError>;
28    async fn ping(&self) -> Result<(), CacheError>;
29}