pub struct BlockCacheManager {
pub config: BcmCacheConfig,
pub hot: HashMap<String, BcmCachedBlock>,
pub warm: HashMap<String, BcmCachedBlock>,
pub cold: HashMap<String, BcmCachedBlock>,
/* private fields */
}Expand description
A multi-tier, policy-driven block cache.
Blocks are stored across three tiers (Cold → Warm → Hot) and migrate
upward based on access frequency thresholds and downward via explicit
demote calls or administrator policy.
Fields§
§config: BcmCacheConfigCache configuration.
hot: HashMap<String, BcmCachedBlock>§warm: HashMap<String, BcmCachedBlock>§cold: HashMap<String, BcmCachedBlock>Implementations§
Source§impl BlockCacheManager
impl BlockCacheManager
Sourcepub fn new(config: BcmCacheConfig) -> Self
pub fn new(config: BcmCacheConfig) -> Self
Create a new BlockCacheManager with the given configuration.
Sourcepub fn insert(&mut self, cid: String, data: Vec<u8>, now: u64) -> bool
pub fn insert(&mut self, cid: String, data: Vec<u8>, now: u64) -> bool
Insert a block into the Cold tier.
Returns false if the CID is already present in any tier.
If the Cold tier is full, attempts eviction before inserting.
Sourcepub fn get(&mut self, cid: &str, now: u64) -> Option<&[u8]>
pub fn get(&mut self, cid: &str, now: u64) -> Option<&[u8]>
Return a reference to the block data, or None if not present.
Updates access_count and last_accessed, then checks whether the
block should be promoted to a higher tier.
Sourcepub fn pin(&mut self, cid: &str) -> bool
pub fn pin(&mut self, cid: &str) -> bool
Mark a block as pinned so it cannot be evicted. Returns false if not found.
Sourcepub fn unpin(&mut self, cid: &str) -> bool
pub fn unpin(&mut self, cid: &str) -> bool
Remove the pin from a block, allowing it to be evicted again. Returns false if not found.
Sourcepub fn evict_to_fit(
&mut self,
tier: CacheTier,
needed_bytes: u64,
now: u64,
) -> u64
pub fn evict_to_fit( &mut self, tier: CacheTier, needed_bytes: u64, now: u64, ) -> u64
Evict unpinned blocks from tier until at least needed_bytes have been freed.
Returns the total number of bytes actually freed. Pinned blocks are never evicted; if only pinned blocks remain, eviction stops early.
Sourcepub fn promote(&mut self, cid: &str, now: u64)
pub fn promote(&mut self, cid: &str, now: u64)
Check whether the block identified by cid should be promoted to a
higher tier based on its current access_count, and move it if so.
Promotion chain:
- Cold → Warm if
access_count >= warm_threshold - Warm → Hot if
access_count >= hot_threshold
Sourcepub fn demote(&mut self, cid: &str, now: u64)
pub fn demote(&mut self, cid: &str, now: u64)
Move a block one tier down. Has no effect if the block is in Cold tier or not found.
Sourcepub fn total_hot_bytes(&self) -> u64
pub fn total_hot_bytes(&self) -> u64
Total bytes used by the Hot tier.
Sourcepub fn total_warm_bytes(&self) -> u64
pub fn total_warm_bytes(&self) -> u64
Total bytes used by the Warm tier.
Sourcepub fn total_cold_bytes(&self) -> u64
pub fn total_cold_bytes(&self) -> u64
Total bytes used by the Cold tier.
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Total bytes across all tiers.
Sourcepub fn remove(&mut self, cid: &str) -> bool
pub fn remove(&mut self, cid: &str) -> bool
Remove a block from the cache, regardless of tier.
Returns false if the block is pinned or not found.
Sourcepub fn tier_of(&self, cid: &str) -> Option<CacheTier>
pub fn tier_of(&self, cid: &str) -> Option<CacheTier>
Return which tier the block lives in, or None if not cached.
Sourcepub fn stats(&self) -> BcmCacheStats
pub fn stats(&self) -> BcmCacheStats
Snapshot of current cache statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockCacheManager
impl RefUnwindSafe for BlockCacheManager
impl Send for BlockCacheManager
impl Sync for BlockCacheManager
impl Unpin for BlockCacheManager
impl UnsafeUnpin for BlockCacheManager
impl UnwindSafe for BlockCacheManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more