Skip to main content

Module block_cache

Module block_cache 

Source
Expand description

In-memory LRU/LFU block cache with TTL-based and size-based eviction.

§Overview

BlockCache is a standalone, synchronous in-memory cache for raw block data (identified by CID strings). It supports three eviction policies:

  • EvictionPolicy::LRU — evict the entry that was accessed least recently.
  • EvictionPolicy::LFU — evict the entry that was accessed least frequently (tie-broken by last-access time so cold entries leave first).
  • EvictionPolicy::TTL — evict expired entries first; if none are expired, fall back to LRU.

Capacity is bounded by both a maximum entry count and a maximum byte footprint. Expired entries are lazily removed on access and can also be swept in bulk via BlockCache::evict_expired.

Structs§

BlockCache
An in-memory cache for raw block data with LRU/LFU/TTL eviction and size-based capacity limits.
CacheConfig
Configuration for a BlockCache.
CacheEntry
A single cached block together with its bookkeeping metadata.
CacheStats
Cumulative statistics for a BlockCache.

Enums§

EvictionPolicy
Determines which entry is chosen for eviction when the cache is full.

Functions§

current_unix_secs
Returns the current Unix time in seconds, falling back to 0 on error.