use crate::core::Result;
use async_trait::async_trait;
#[async_trait::async_trait]
pub trait CacheTrait: Send + Sync {
async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
async fn set(&self, key: &str, value: Vec<u8>, ttl: Option<std::time::Duration>) -> Result<()>;
async fn delete(&self, key: &str) -> Result<()>;
}
pub trait MetricsTrait: Send + Sync {
fn increment_counter(&self, name: &str, tags: &[(&str, &str)]);
fn record_histogram(&self, name: &str, value: f64, tags: &[(&str, &str)]);
fn set_gauge(&self, name: &str, value: f64, tags: &[(&str, &str)]);
}
pub struct MemoryCache {
}
impl MemoryCache {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl CacheTrait for MemoryCache {
async fn get(&self, _key: &str) -> Result<Option<Vec<u8>>> {
Ok(None)
}
async fn set(&self, _key: &str, _value: Vec<u8>, _ttl: Option<std::time::Duration>) -> Result<()> {
Ok(())
}
async fn delete(&self, _key: &str) -> Result<()> {
Ok(())
}
}
pub struct SimpleMetrics {
}
impl SimpleMetrics {
pub fn new() -> Self {
Self {}
}
}
impl MetricsTrait for SimpleMetrics {
fn increment_counter(&self, _name: &str, _tags: &[(&str, &str)]) {
}
fn record_histogram(&self, _name: &str, _value: f64, _tags: &[(&str, &str)]) {
}
fn set_gauge(&self, _name: &str, _value: f64, _tags: &[(&str, &str)]) {
}
}
#[async_trait::async_trait]
impl crate::core::scanner_builder::CacheTrait for MemoryCache {
async fn get(&self, key: &str) -> crate::core::Result<Option<Vec<u8>>> {
<Self as CacheTrait>::get(self, key).await.map_err(|e| crate::core::SolanaRecoverError::InternalError(e.to_string()))
}
async fn set(&self, key: &str, value: Vec<u8>, ttl: Option<std::time::Duration>) -> crate::core::Result<()> {
<Self as CacheTrait>::set(self, key, value, ttl).await.map_err(|e| crate::core::SolanaRecoverError::InternalError(e.to_string()))
}
async fn delete(&self, key: &str) -> crate::core::Result<()> {
<Self as CacheTrait>::delete(self, key).await.map_err(|e| crate::core::SolanaRecoverError::InternalError(e.to_string()))
}
}
impl crate::core::scanner_builder::MetricsTrait for SimpleMetrics {
fn increment_counter(&self, _name: &str, _tags: &[(&str, &str)]) {
}
fn record_histogram(&self, _name: &str, _value: f64, _tags: &[(&str, &str)]) {
}
fn set_gauge(&self, _name: &str, _value: f64, _tags: &[(&str, &str)]) {
}
}