mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 02:20:43 +08:00
This improves response time of: - GET /api/v1/projects/<RID>/tree/<OID>/ from 205.71ms down to 376.4µs - GET /api/v1/projects/<RID>/tree/<OID>/.nix from 111.06ms down to 351.70µs Signed-off-by: xphoniex <dj.2dixx@gmail.com>
23 lines
456 B
Rust
23 lines
456 B
Rust
use std::num::NonZeroUsize;
|
|
use std::sync::Arc;
|
|
|
|
use lru::LruCache;
|
|
use tokio::sync::Mutex;
|
|
|
|
use radicle::prelude::Id;
|
|
use radicle_surf::Oid;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Cache {
|
|
pub tree: Arc<Mutex<LruCache<(Id, Oid, String), serde_json::Value>>>,
|
|
}
|
|
|
|
impl Cache {
|
|
/// Creates a new cache of the given size.
|
|
pub fn new(size: NonZeroUsize) -> Self {
|
|
Cache {
|
|
tree: Arc::new(Mutex::new(LruCache::new(size))),
|
|
}
|
|
}
|
|
}
|