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:
17
src/notecache.rs
Normal file
17
src/notecache.rs
Normal 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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user