Files
heartwood/radicle-httpd/src/cache.rs
T
xphoniex 8a61aece01 httpd: Add a cache for /tree
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>
2023-07-25 13:10:58 +02:00

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))),
}
}
}