Skip to content

Caching Strategy

Optimize blockchain queries with smart caching decisions based on data stability patterns and automatic cache management.

The system categorizes blockchain data by stability for optimal performance:

  • Historical blocks and transactions
  • Finalized transaction receipts
  • Past event logs with specific block ranges
  • Contract code and creation data
  • Recent block data
  • Account balances
  • Contract state queries
  • Network information
  • Latest block number
  • Pending transactions
  • Real-time network stats
  • Dynamic contract state
  • Transaction submissions (not supported)
  • Account-specific operations requiring fresh data
  • Debug and trace methods

Cache keys are generated deterministically using chain ID, method name, and parameter serialization:

// Cache key format
const key = `${chainId}:${method}:${JSON.stringify(params)}`;

The caching system:

  1. Checks cache first for performance optimization
  2. Executes function if cache miss occurs
  3. Stores result with appropriate TTL based on data type
  4. Returns cached results with metadata indicating cache status

Cached responses include performance metrics:

  • Cache hit/miss status
  • Provider information
  • Latency measurements
  • Request metadata

This enables monitoring of cache effectiveness and query optimization.