Caching Strategy
Caching Strategy
Section titled “Caching Strategy”Optimize blockchain queries with smart caching decisions based on data stability patterns and automatic cache management.
Cache Types
Section titled “Cache Types”The system categorizes blockchain data by stability for optimal performance:
Immutable Data (7 days TTL)
Section titled “Immutable Data (7 days TTL)”- Historical blocks and transactions
- Finalized transaction receipts
- Past event logs with specific block ranges
- Contract code and creation data
Semi-Stable Data (15 seconds TTL)
Section titled “Semi-Stable Data (15 seconds TTL)”- Recent block data
- Account balances
- Contract state queries
- Network information
Volatile Data (3 seconds TTL)
Section titled “Volatile Data (3 seconds TTL)”- Latest block number
- Pending transactions
- Real-time network stats
- Dynamic contract state
No Caching
Section titled “No Caching”- Transaction submissions (not supported)
- Account-specific operations requiring fresh data
- Debug and trace methods
Cache Key Generation
Section titled “Cache Key Generation”Cache keys are generated deterministically using chain ID, method name, and parameter serialization:
// Cache key formatconst key = `${chainId}:${method}:${JSON.stringify(params)}`;Cache Behavior
Section titled “Cache Behavior”The caching system:
- Checks cache first for performance optimization
- Executes function if cache miss occurs
- Stores result with appropriate TTL based on data type
- Returns cached results with metadata indicating cache status
Cache Performance
Section titled “Cache Performance”Cached responses include performance metrics:
- Cache hit/miss status
- Provider information
- Latency measurements
- Request metadata
This enables monitoring of cache effectiveness and query optimization.