A three-layer cache system designed for blockchain node environments
blockchain-node-cache is a three-tier cache system implemented in Rust,
designed for use within blockchain node infrastructures.
The cache is structured into three hierarchical layers:
Local → Global → Database
Each layer represents a staged key-value state:
- Local Layer – Temporary, request-scoped cache
- Global Layer – Shared in-memory cache
- Database Layer – Persistent storage backend
- When a layer commits, its state is propagated upward.
- When a layer rolls back, modified key-value pairs are discarded.
- This design enables controlled state propagation and transactional-style cache behavior.
The system is implemented with a generic database abstraction.
Through a trait-based interface, the database backend is defined as a generic type parameter, allowing integration with any storage engine as long as it satisfies the required trait contract.
This ensures:
- Database-agnostic design
- Flexible backend replacement
- Strong type safety via Rust generics
The trait module defines the core cache interface contract.
src/
├─ cache/
│ ├─ db.rs
│ ├─ global.rs
│ ├─ local.rs
│ └─ mod.rs
├─ lib.rs
└─ trait.rs
cache/
Contains the layered cache implementation:
local.rs – Local cache layer logic
global.rs – Global shared cache layer
db.rs – Database layer integration
mod.rs – Cache module wiring
trait.rs
Defines the core cache interface and database abstraction contract.
lib.rs
Library entry point.
Language: Rust
Concurrency Map: scc::HashMap
Architecture: Layered Cache System (Local → Global → DB)
Design Pattern: Trait-based Generic Abstraction
Three-layer hierarchical cache
Commit & rollback propagation model
Generic database abstraction
Pluggable storage backend
Concurrent-safe in-memory cache (via scc)