tetrio_api/http/caches/
cache.rs

1use std::fmt::Debug;
2
3use async_trait::async_trait;
4use serde::{de::DeserializeOwned, Serialize};
5
6use crate::{http::error::Error, models::packet::{Packet, SuccessPacket}};
7
8
9
10#[async_trait]
11pub trait CacheHandler<ErrorT: std::error::Error + Sync + Send + Debug> {
12    type CachingError: std::error::Error + Sync + Send + Debug;
13    /// A method to implement to get a value from the cache
14    /// It should NOT return an error if the value is not in the cache
15    /// If the value is not in the cache, it should return Ok(None)
16    async fn try_get_cache<T: DeserializeOwned + Serialize>(&self, cache_key: &str) -> Result<Option<Packet<T>>, Error<ErrorT, Self::CachingError>>;
17
18    /// A method to implement to set a value in the cache
19    /// It should return an error if the value could not be set
20    async fn cache_value<T: DeserializeOwned + Serialize + Send + Sync>(&self, cache_key: &str, cache_value: SuccessPacket<T>) -> Result<(), Error<ErrorT, Self::CachingError>>;
21}