use lru::LruCache; use parking_lot::Mutex; use types::{BlobsSidecar, EthSpec, Hash256}; pub const DEFAULT_BLOB_CACHE_SIZE: usize = 10; /// A cache blobs by beacon block root. pub struct BlobCache { blobs: Mutex>>, } #[derive(Hash, PartialEq, Eq)] struct BlobCacheId(Hash256); impl Default for BlobCache { fn default() -> Self { BlobCache { blobs: Mutex::new(LruCache::new(DEFAULT_BLOB_CACHE_SIZE)), } } } impl BlobCache { pub fn put(&self, beacon_block: Hash256, blobs: BlobsSidecar) -> Option> { self.blobs.lock().put(BlobCacheId(beacon_block), blobs) } pub fn pop(&self, root: &Hash256) -> Option> { self.blobs.lock().pop(&BlobCacheId(*root)) } }