Skip to main content

Module cache

Module cache 

Source
Expand description

Cache Module

High-performance caching infrastructure for RedDB.

§Components

  • sieve: SIEVE page cache for database pages (O(1) operations)
  • blob: Byte-oriented L1 cache for exact-key cached blobs
  • result: Query result cache with dependency-based invalidation
  • aggregates: Precomputed aggregations (COUNT, SUM, AVG, etc.)
  • spill: Graph spill-to-disk for memory-limited environments

§Architecture (inspired by Turso/Milvus/Neo4j)

┌────────────────────────────────────────────────────────┐
│                    Query Layer                         │
├────────────────────────────────────────────────────────┤
│  Result Cache   │  Materialized Views  │  Plan Cache   │
├────────────────────────────────────────────────────────┤
│           Aggregation Cache (COUNT/SUM/AVG)            │
├────────────────────────────────────────────────────────┤
│   SIEVE Page Cache    │     Spill Manager              │
├────────────────────────────────────────────────────────┤
│                   Storage Engine                       │
└────────────────────────────────────────────────────────┘

Modules§

aggregates
Aggregation Cache
bgwriter
Background writer task — Post-MVP credibility item.
blob
Byte-oriented Blob Cache.
compressor
L2 Blob Compressor.
extended_ttl
Extended TTL Policy & Effective Expiry
promotion_pool
Async promotion pool — turbo module for off-CPU L1 cache promotion.
result
Query Result Cache
ring
Fixed-size circular page ring used by super::strategy::BufferAccessStrategy.
sieve
SIEVE Page Cache
spill
Graph Spill Manager
strategy
Buffer access strategies for the page cache.
sweeper
Bounded Blob Cache sweeper — admin maintenance for L1 expirations and L2 orphan-chain reclamation.

Structs§

AggCacheStats
Aggregation cache statistics
AggregationCache
Cache for precomputed aggregations
AsyncPromotionPool
Bounded, drop-oldest async promotion pool.
BlobCache
Sharded, byte-bounded blob cache with optional durable L2 backing.
BlobCacheConfig
BlobCacheHit
BlobCachePolicy
BlobCachePut
BlobCacheStats
BufferRing
Fixed-capacity circular cache.
CacheConfig
Cache configuration
CacheKey
Cache key for query results
CachePolicy
Policy for cache entry behavior
CacheStats
Cache statistics
CardinalityEstimate
Cardinality estimator using HyperLogLog-style counting
CompressOpts
Configuration knobs for L2BlobCompressor::compress.
EffectiveExpiry
Stateless calculator for effective expiry decisions.
ExtendedTtlPolicy
Extended TTL configuration that augments a base [BlobCachePolicy].
L2BlobCompressor
Stateless compressor for L2 blob payloads.
MaterializedViewCache
Cache for materialized views
MaterializedViewDef
Definition of a materialized view
NumericAgg
Numeric aggregation value
PageCache
SIEVE Page Cache
PoolOpts
Configuration for the promotion pool.
PromotionMetrics
Snapshot of the pool’s atomic counters. Returned by metrics().
PromotionRequest
A single async promotion request handed to the pool by BlobCache::get (or, in tests, by the test harness).
ResultCache
LRU cache for query results with memory management
ResultCacheStats
Cache statistics
SpillConfig
Configuration for the spill manager
SpillManager
Manages memory limits by spilling cold data to disk
SpillStats
Statistics about spill operations
SpillableGraph
A graph wrapper that automatically spills to disk when memory limit is reached

Enums§

AggValue
Value type for aggregation operations
BufferAccessStrategy
How a caller intends to access the page cache.
CacheError
CompressError
Errors produced by the compressor.
Compressed
Storage-ready representation of a blob payload after the compressor has inspected it. Raw is byte-equivalent to the input; Zstd carries an encoded payload plus the original byte length for verification.
ExpiryDecision
Outcome of an EffectiveExpiry::compute call.
L1Admission
L2Compression
Switch for L2 zstd compression (issue #192, lane 2/5).
RefreshPolicy
How to refresh a materialized view
ScheduleOutcome
Result of AsyncPromotionPool::schedule.
SpillError
Error types for spill operations

Constants§

DEFAULT_BLOB_L1_BYTES_MAX
DEFAULT_BLOB_L2_BYTES_MAX
DEFAULT_BLOB_MAX_NAMESPACES
METRIC_CACHE_BLOB_L1_BYTES_IN_USE
METRIC_CACHE_BLOB_L2_BYTES_IN_USE
METRIC_CACHE_BLOB_L2_FULL_REJECTIONS_TOTAL
METRIC_CACHE_VERSION_MISMATCH_TOTAL

Functions§

archive_blob_cache_l2
Archive the L2 pager file + control sidecar to backend under {prefix}l2.pager and {prefix}l2.ctl. Returns the number of files uploaded (0..=2).
restore_blob_cache_l2
Restore the L2 pager file + control sidecar from backend’s {prefix}l2.pager and {prefix}l2.ctl keys into l2_path (and its <l2_path>.blob-cache.ctl sibling). Returns the number of files downloaded.

Type Aliases§

PageId
Page identifier type
PromotionExecutor
The closure that actually performs the L1 promotion. Injected at construction so this module has no compile-time dependency on BlobCache.