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