cache.rs
1 use std::num::NonZeroUsize; 2 use std::sync::Arc; 3 4 use lru::LruCache; 5 use tokio::sync::Mutex; 6 7 use radicle::prelude::RepoId; 8 use radicle_surf::Oid; 9 10 #[derive(Clone)] 11 pub struct Cache { 12 pub tree: Arc<Mutex<LruCache<(RepoId, Oid, String), serde_json::Value>>>, 13 } 14 15 impl Cache { 16 /// Creates a new cache of the given size. 17 pub fn new(size: NonZeroUsize) -> Self { 18 Cache { 19 tree: Arc::new(Mutex::new(LruCache::new(size))), 20 } 21 } 22 }