pub struct StateCache { /* private fields */ }Expand description
Multi-layer TTL cache for on-chain state.
Keyed by address ([u8; 20]) for per-market data, or by perp ID
([u8; 32]) for per-perp data. The USDC balance is a singleton.
Implementations§
Source§impl StateCache
impl StateCache
Sourcepub fn new(config: StateCacheConfig) -> Self
pub fn new(config: StateCacheConfig) -> Self
Create a new cache with the given TTL configuration.
Sourcepub fn get_fees(&self, addr: &[u8; 20], now_ts: u64) -> Option<&CachedFees>
pub fn get_fees(&self, addr: &[u8; 20], now_ts: u64) -> Option<&CachedFees>
Get cached fees for a market address, or None if stale/absent.
Sourcepub fn put_fees(&mut self, addr: [u8; 20], value: CachedFees, now_ts: u64)
pub fn put_fees(&mut self, addr: [u8; 20], value: CachedFees, now_ts: u64)
Cache fees for a market address.
Sourcepub fn get_bounds(&self, addr: &[u8; 20], now_ts: u64) -> Option<&CachedBounds>
pub fn get_bounds(&self, addr: &[u8; 20], now_ts: u64) -> Option<&CachedBounds>
Get cached bounds for a market address, or None if stale/absent.
Sourcepub fn put_bounds(&mut self, addr: [u8; 20], value: CachedBounds, now_ts: u64)
pub fn put_bounds(&mut self, addr: [u8; 20], value: CachedBounds, now_ts: u64)
Cache bounds for a market address.
Sourcepub fn get_mark_price(&self, perp_id: &[u8; 32], now_ts: u64) -> Option<f64>
pub fn get_mark_price(&self, perp_id: &[u8; 32], now_ts: u64) -> Option<f64>
Get cached mark price for a perp, or None if stale/absent.
Sourcepub fn put_mark_price(&mut self, perp_id: [u8; 32], price: f64, now_ts: u64)
pub fn put_mark_price(&mut self, perp_id: [u8; 32], price: f64, now_ts: u64)
Cache a mark price for a perp.
Sourcepub fn get_funding_rate(&self, perp_id: &[u8; 32], now_ts: u64) -> Option<f64>
pub fn get_funding_rate(&self, perp_id: &[u8; 32], now_ts: u64) -> Option<f64>
Get cached funding rate for a perp, or None if stale/absent.
Sourcepub fn put_funding_rate(&mut self, perp_id: [u8; 32], rate: f64, now_ts: u64)
pub fn put_funding_rate(&mut self, perp_id: [u8; 32], rate: f64, now_ts: u64)
Cache a funding rate for a perp.
Sourcepub fn get_usdc_balance(&self, now_ts: u64) -> Option<f64>
pub fn get_usdc_balance(&self, now_ts: u64) -> Option<f64>
Get cached USDC balance, or None if stale/absent.
Sourcepub fn put_usdc_balance(&mut self, balance: f64, now_ts: u64)
pub fn put_usdc_balance(&mut self, balance: f64, now_ts: u64)
Cache the USDC balance.
Sourcepub fn invalidate_fast_layer(&mut self)
pub fn invalidate_fast_layer(&mut self)
Invalidate all fast-layer data (prices, funding, balance).
Call on new-block events. The slow layer (fees, bounds) is preserved.
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Invalidate everything (both layers).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StateCache
impl RefUnwindSafe for StateCache
impl Send for StateCache
impl Sync for StateCache
impl Unpin for StateCache
impl UnsafeUnpin for StateCache
impl UnwindSafe for StateCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more