teaql_tool_extra/
cache.rs1use moka::sync::Cache;
2use std::time::Duration;
3
4pub struct CacheTool {
5 string_cache: Cache<String, String>,
6}
7
8impl CacheTool {
9 pub fn new() -> Self {
10 let string_cache = Cache::builder()
11 .time_to_live(Duration::from_secs(60 * 60)) .build();
13 Self { string_cache }
14 }
15
16 pub fn put(&self, key: &str, value: &str) {
17 self.string_cache.insert(key.to_string(), value.to_string());
18 }
19
20 pub fn get(&self, key: &str) -> Option<String> {
21 self.string_cache.get(key)
22 }
23}
24
25impl Default for CacheTool {
26 fn default() -> Self {
27 Self::new()
28 }
29}