Expand description
Response caching layer for RPC transports.
CacheTransport wraps any Arc<dyn RpcTransport> and caches successful
responses for configurable methods. Cache keys are computed as a hash of
(method, params) so identical requests share a single cache entry.
§Tiered Caching
When a CacheTierResolver is configured, the cache classifies each
method+params pair into one of four CacheTiers, each with its own TTL:
- Immutable — results that never change (1 hour TTL).
- SemiStable — results that change infrequently (5 minutes TTL).
- Volatile — results that change frequently (2 seconds TTL).
- NeverCache — write methods and subscriptions (never cached).
Without a tier resolver, the cache falls back to the flat default_ttl
behavior for all methods listed in cacheable_methods.
§Finality Awareness
The CacheTransport::invalidate_for_reorg method removes cached entries
that reference blocks at or above a given block number, enabling safe
cache invalidation during chain reorganizations.
§Design
- Only explicitly cacheable methods are cached (opt-in via
CacheConfig). - Expired entries are evicted lazily on access.
- When the cache exceeds
max_entries, the oldest entry is evicted (LRU-ish). - Thread-safe: the cache is behind a
Mutexand the struct isSend + Sync.
Structs§
- Cache
Config - Configuration for the response cache.
- Cache
Stats - Aggregate cache statistics.
- Cache
Tier Resolver - Determines the
CacheTierfor a given RPC request. - Cache
Transport - A caching wrapper around an RPC transport.
Enums§
- Cache
Tier - Classification of an RPC method’s caching behavior.