aboutsummaryrefslogtreecommitdiff
path: root/cache/src
diff options
context:
space:
mode:
Diffstat (limited to 'cache/src')
-rw-r--r--cache/src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/cache/src/lib.rs b/cache/src/lib.rs
index 0a7a2f1..117b0d2 100644
--- a/cache/src/lib.rs
+++ b/cache/src/lib.rs
@@ -7,12 +7,14 @@ mod helper;
use anyhow::{Context, Result, anyhow};
pub use helper::{EscapeKey, HashKey};
+use humansize::{DECIMAL, SizeFormatter};
use jellykv::BlobStorage;
use log::{info, warn};
use serde::{Deserialize, Serialize};
use std::{
any::Any,
collections::{BTreeMap, HashMap},
+ fmt::Write,
hash::{DefaultHasher, Hash, Hasher},
sync::{
Arc, LazyLock, Mutex, RwLock,
@@ -168,4 +170,15 @@ impl Cache {
humansize::format_size(reduction, humansize::DECIMAL)
);
}
+
+ pub fn debug_info(&self) -> Result<String> {
+ let mut o = String::new();
+ let msize = self.memory_cache_size.load(Ordering::Relaxed);
+ let mcount = self.memory_cache.read().unwrap().len();
+ let msize = SizeFormatter::new(msize, DECIMAL).to_string();
+ writeln!(o, "in-memory cache size: {msize:>12}")?;
+ writeln!(o, "in-memory cache obj count: {mcount:>12}")?;
+ write!(o, "{}", self.storage.debug_info()?)?;
+ Ok(o)
+ }
}