mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
implement memory pool for bookmark index
This commit is contained in:
parent
74e9daeddb
commit
7b9bd95c09
2 changed files with 69 additions and 3 deletions
38
src/profile/bookmark/memory.rs
Normal file
38
src/profile/bookmark/memory.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use gtk::glib::DateTime;
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
/// Reduce disk usage by cache results in memory
|
||||
pub struct Memory {
|
||||
index: RefCell<HashMap<String, DateTime>>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
// Constructors
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
index: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Set new record
|
||||
/// * replace existing record with new value
|
||||
pub fn set(&self, request: String, time: DateTime) {
|
||||
// Borrow index to update
|
||||
let mut index = self.index.borrow_mut();
|
||||
|
||||
// Cleanup previous record
|
||||
if index.get(&request).is_some() {
|
||||
index.remove(&request);
|
||||
}
|
||||
|
||||
// Insert new record with actual data
|
||||
index.insert(request, time);
|
||||
}
|
||||
|
||||
pub fn is_exist(&self, request: &str) -> bool {
|
||||
self.index.borrow().get(request).is_some()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue