use core::time::Duration;
use indexmap::{IndexMap, IndexSet};
use serde::{de::DeserializeOwned, Serialize};
use std::{hash::Hash, time::SystemTime};
use crate::tina::{data::AppResult, server::application::Application};
#[async_trait]
pub trait ICacheService: Send + Sync + 'static {
async fn set_cache_object<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
value: &T,
) -> AppResult<()>;
async fn set_cache_object_with_timeout<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
value: &T,
timeout: Duration,
) -> AppResult<()>;
async fn expire(&self, application: &Application, key: &str, timeout: Duration) -> AppResult<bool>;
async fn get_cache_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<Option<T>>;
async fn delete_object(&self, application: &Application, key: &str) -> AppResult<bool>;
async fn delete_objects(&self, application: &Application, keys: &[&str]) -> AppResult<i64>;
async fn set_cache_objects<E: Serialize + Send + Sync + 'static, T: AsRef<[E]> + Send + 'static>(
&self,
application: &Application,
key: &str,
datas: T,
) -> AppResult<i64>;
async fn get_cache_objects_list<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<Vec<T>>;
async fn get_cache_objects_set<T: DeserializeOwned + Eq + Hash + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<IndexSet<T>>;
async fn set_cache_map<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
map: &IndexMap<String, T>,
) -> AppResult<()>;
async fn get_cache_map<T: DeserializeOwned + Send + Sync + 'static, Map: FromIterator<(String, T)>>(
&self,
application: &Application,
key: &str,
) -> AppResult<Map>;
async fn set_cache_map_object<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkey: &str,
value: &T,
) -> AppResult<()>;
async fn get_cache_map_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkey: &str,
) -> AppResult<Option<T>>;
async fn delete_map_object(&self, application: &Application, key: &str, hkey: &str) -> AppResult<bool>;
async fn get_multi_cache_map_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkeys: &[&str],
) -> AppResult<Vec<T>>;
async fn keys(&self, application: &Application, pattern: &str) -> AppResult<Vec<String>>;
async fn time(&self, application: &Application) -> AppResult<SystemTime>;
}
pub struct NoCacheService;
#[allow(unused_variables)]
#[async_trait]
impl ICacheService for NoCacheService {
async fn set_cache_object<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
value: &T,
) -> AppResult<()> {
unimplemented!()
}
async fn set_cache_object_with_timeout<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
value: &T,
timeout: Duration,
) -> AppResult<()> {
unimplemented!()
}
async fn expire(&self, application: &Application, key: &str, timeout: Duration) -> AppResult<bool> {
unimplemented!()
}
async fn get_cache_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<Option<T>> {
unimplemented!()
}
async fn delete_object(&self, application: &Application, key: &str) -> AppResult<bool> {
unimplemented!()
}
async fn delete_objects(&self, application: &Application, keys: &[&str]) -> AppResult<i64> {
unimplemented!()
}
async fn set_cache_objects<E: Serialize + Send + Sync + 'static, T: AsRef<[E]> + Send + 'static>(
&self,
application: &Application,
key: &str,
datas: T,
) -> AppResult<i64> {
unimplemented!()
}
async fn get_cache_objects_list<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<Vec<T>> {
unimplemented!()
}
async fn get_cache_objects_set<T: DeserializeOwned + Eq + Hash + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
) -> AppResult<IndexSet<T>> {
unimplemented!()
}
async fn set_cache_map<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
map: &IndexMap<String, T>,
) -> AppResult<()> {
unimplemented!()
}
async fn get_cache_map<T: DeserializeOwned + Send + Sync + 'static, Map: FromIterator<(String, T)>>(
&self,
application: &Application,
key: &str,
) -> AppResult<Map> {
unimplemented!()
}
async fn set_cache_map_object<T: Serialize + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkey: &str,
value: &T,
) -> AppResult<()> {
unimplemented!()
}
async fn get_cache_map_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkey: &str,
) -> AppResult<Option<T>> {
unimplemented!()
}
async fn delete_map_object(&self, application: &Application, key: &str, hkey: &str) -> AppResult<bool> {
unimplemented!()
}
async fn get_multi_cache_map_object<T: DeserializeOwned + Send + Sync + 'static>(
&self,
application: &Application,
key: &str,
hkeys: &[&str],
) -> AppResult<Vec<T>> {
unimplemented!()
}
async fn keys(&self, application: &Application, pattern: &str) -> AppResult<Vec<String>> {
unimplemented!()
}
async fn time(&self, application: &Application) -> AppResult<SystemTime> {
unimplemented!()
}
}