pub trait Cache {
type Item;
type Client;
// Required methods
async fn new() -> Self;
async fn get_con(&self) -> Self::Client;
async fn get(&self, id: Self::Item) -> Option<String>;
async fn set(&self, id: Self::Item, content: Self::Item) -> bool;
async fn update(&self, id: Self::Item, content: Self::Item) -> bool;
async fn remove(&self, id: Self::Item) -> bool;
async fn remove_starting_with(&self, id: Self::Item) -> bool;
async fn incr(&self, id: Self::Item) -> bool;
async fn decr(&self, id: Self::Item) -> bool;
async fn get_timed<T: Serialize + DeserializeOwned>(
&self,
id: Self::Item,
) -> Option<TimedObject<T>>;
async fn set_timed<T: Serialize + DeserializeOwned>(
&self,
id: Self::Item,
content: T,
) -> bool;
}
Expand description
A simple cache “database”.
Required Associated Types§
Required Methods§
Sourceasync fn set(&self, id: Self::Item, content: Self::Item) -> bool
async fn set(&self, id: Self::Item, content: Self::Item) -> bool
Set a cache object by its identifier and content
§Arguments
id
-String
of the object’s idcontent
-String
of the object’s content
Sourceasync fn update(&self, id: Self::Item, content: Self::Item) -> bool
async fn update(&self, id: Self::Item, content: Self::Item) -> bool
Update a cache object by its identifier and content
§Arguments
id
-String
of the object’s idcontent
-String
of the object’s content
Sourceasync fn remove_starting_with(&self, id: Self::Item) -> bool
async fn remove_starting_with(&self, id: Self::Item) -> bool
Remove a cache object by its identifier(’s start)
§Arguments
id
-String
of the object’s id(’s start)
Sourceasync fn get_timed<T: Serialize + DeserializeOwned>(
&self,
id: Self::Item,
) -> Option<TimedObject<T>>
async fn get_timed<T: Serialize + DeserializeOwned>( &self, id: Self::Item, ) -> Option<TimedObject<T>>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.