crdb_cache/
binaries_cache.rs1use crdb_core::BinPtr;
2use std::{
3 collections::HashMap,
4 sync::{Arc, Weak},
5};
6
7pub struct BinariesCache {
8 data: HashMap<BinPtr, Weak<[u8]>>,
9}
10
11impl BinariesCache {
12 pub fn new() -> BinariesCache {
13 BinariesCache {
14 data: HashMap::new(),
15 }
16 }
17
18 pub fn insert(&mut self, id: BinPtr, value: Weak<[u8]>) {
19 self.data.insert(id, value);
20 }
21
22 pub fn get(&self, binary_id: &BinPtr) -> Option<Arc<[u8]>> {
23 self.data.get(binary_id).and_then(|b| b.upgrade())
24 }
25}
26
27impl Default for BinariesCache {
28 fn default() -> BinariesCache {
29 BinariesCache::new()
30 }
31}