oiseau/cache/mod.rs
1#![allow(async_fn_in_trait)]
2
3#[cfg(feature = "redis")]
4pub mod redis;
5
6#[cfg(not(feature = "redis"))]
7pub mod no_cache;
8
9/// A simple cache "database".
10pub trait Cache {
11 type Item;
12 type Client;
13
14 /// Create a new [`Cache`].
15 async fn new() -> Self;
16 /// Get a connection to the cache.
17 async fn get_con(&self) -> Self::Client;
18
19 /// Get a cache object by its identifier
20 ///
21 /// # Arguments
22 /// * `id` - `String` of the object's id
23 async fn get(&self, id: Self::Item) -> Option<String>;
24 /// Set a cache object by its identifier and content
25 ///
26 /// # Arguments
27 /// * `id` - `String` of the object's id
28 /// * `content` - `String` of the object's content
29 async fn set(&self, id: Self::Item, content: Self::Item) -> bool;
30 /// Update a cache object by its identifier and content
31 ///
32 /// # Arguments
33 /// * `id` - `String` of the object's id
34 /// * `content` - `String` of the object's content
35 async fn update(&self, id: Self::Item, content: Self::Item) -> bool;
36 /// Remove a cache object by its identifier
37 ///
38 /// # Arguments
39 /// * `id` - `String` of the object's id
40 async fn remove(&self, id: Self::Item) -> bool;
41 /// Remove a cache object by its identifier('s start)
42 ///
43 /// # Arguments
44 /// * `id` - `String` of the object's id('s start)
45 async fn remove_starting_with(&self, id: Self::Item) -> bool;
46 /// Increment a cache object by its identifier
47 ///
48 /// # Arguments
49 /// * `id` - `String` of the object's id
50 async fn incr(&self, id: Self::Item) -> bool;
51 /// Decrement a cache object by its identifier
52 ///
53 /// # Arguments
54 /// * `id` - `String` of the object's id
55 async fn decr(&self, id: Self::Item) -> bool;
56}