pub struct CacheTransport { /* private fields */ }Expand description
A caching wrapper around an RPC transport.
Only methods listed in CacheConfig::cacheable_methods are cached.
All other requests pass straight through to the inner transport.
Implementations§
Source§impl CacheTransport
impl CacheTransport
Sourcepub fn new(inner: Arc<dyn RpcTransport>, config: CacheConfig) -> Self
pub fn new(inner: Arc<dyn RpcTransport>, config: CacheConfig) -> Self
Create a new caching wrapper.
Sourcepub async fn send(
&self,
req: JsonRpcRequest,
) -> Result<JsonRpcResponse, TransportError>
pub async fn send( &self, req: JsonRpcRequest, ) -> Result<JsonRpcResponse, TransportError>
Send a request, returning a cached response when available.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Clear all cached entries.
Sourcepub fn invalidate_method(&self, method: &str)
pub fn invalidate_method(&self, method: &str)
Clear cached entries for the given method name.
Each CacheEntry stores its method name, so we can filter precisely
and only remove entries belonging to the targeted method.
Sourcepub fn invalidate_for_reorg(&self, from_block: u64)
pub fn invalidate_for_reorg(&self, from_block: u64)
Invalidate all cached entries that reference blocks at or above
from_block.
This is used during chain reorganizations: when a reorg is detected
starting at from_block, all cached data that might reference the
now-invalid chain segment must be removed.
Entries without a detectable block_ref (i.e., block_ref is None)
are not removed — they are either block-agnostic (like eth_chainId)
or their block association could not be determined.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Return a snapshot of cache statistics.