notecache: add initial in-memory notecache

This is useful for things like relative time strings and other
transient note cache state

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-02-15 13:03:46 -08:00
parent c246b9d92f
commit 2ce2d4cc70
3 changed files with 27 additions and 0 deletions

17
src/notecache.rs Normal file
View File

@@ -0,0 +1,17 @@
use crate::time::time_ago_since;
use crate::timecache::TimeCached;
use std::time::Duration;
pub struct NoteCache {
reltime: TimeCached<String>,
}
impl NoteCache {
pub fn new(created_at: u64) -> Self {
let reltime = TimeCached::new(
Duration::from_secs(1),
Box::new(move || time_ago_since(created_at)),
);
NoteCache { reltime }
}
}