use async_trait::async_trait;
use indexmap::IndexMap;
use std::time::SystemTime;
use vantage_core::Result;
use vantage_types::Record;
mod mem;
mod noop;
mod redb;
pub use mem::MemCache;
pub use noop::NoCache;
pub use redb::RedbCache;
#[derive(Clone, Debug)]
pub struct CachedRows {
pub rows: IndexMap<String, Record<ciborium::Value>>,
pub fetched_at: SystemTime,
}
impl CachedRows {
pub fn new(rows: IndexMap<String, Record<ciborium::Value>>) -> Self {
Self {
rows,
fetched_at: SystemTime::now(),
}
}
}
#[async_trait]
pub trait Cache: Send + Sync {
async fn get(&self, key: &str) -> Result<Option<CachedRows>>;
async fn put(&self, key: &str, rows: CachedRows) -> Result<()>;
async fn invalidate_prefix(&self, prefix: &str) -> Result<()>;
}