Skip to main content

CacheTransport

Struct CacheTransport 

Source
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

Source

pub fn new(inner: Arc<dyn RpcTransport>, config: CacheConfig) -> Self

Create a new caching wrapper.

Source

pub async fn send( &self, req: JsonRpcRequest, ) -> Result<JsonRpcResponse, TransportError>

Send a request, returning a cached response when available.

Source

pub fn invalidate(&self)

Clear all cached entries.

Source

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.

Source

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.

Source

pub fn stats(&self) -> CacheStats

Return a snapshot of cache statistics.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more