1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use ckb_app_config::StoreConfig;
use ckb_types::{
bytes::Bytes,
core::{HeaderView, TransactionView, UncleBlockVecView},
packed::{Byte32, ProposalShortIdVec},
};
use ckb_util::Mutex;
use lru::LruCache;
pub struct StoreCache {
pub headers: Mutex<LruCache<Byte32, HeaderView>>,
pub cell_data: Mutex<LruCache<Vec<u8>, (Bytes, Byte32)>>,
pub block_proposals: Mutex<LruCache<Byte32, ProposalShortIdVec>>,
pub block_tx_hashes: Mutex<LruCache<Byte32, Vec<Byte32>>>,
pub block_uncles: Mutex<LruCache<Byte32, UncleBlockVecView>>,
pub cellbase: Mutex<LruCache<Byte32, TransactionView>>,
}
impl Default for StoreCache {
fn default() -> Self {
StoreCache::from_config(StoreConfig::default())
}
}
impl StoreCache {
pub fn from_config(config: StoreConfig) -> Self {
StoreCache {
headers: Mutex::new(LruCache::new(config.header_cache_size)),
cell_data: Mutex::new(LruCache::new(config.cell_data_cache_size)),
block_proposals: Mutex::new(LruCache::new(config.block_proposals_cache_size)),
block_tx_hashes: Mutex::new(LruCache::new(config.block_tx_hashes_cache_size)),
block_uncles: Mutex::new(LruCache::new(config.block_uncles_cache_size)),
cellbase: Mutex::new(LruCache::new(config.cellbase_cache_size)),
}
}
}