pub trait BlockWindowCache: Send + Sync {
// Required methods
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
) -> Pin<Box<dyn Future<Output = Option<DailyBlockWindow>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn insert<'life0, 'async_trait>(
&'life0 self,
key: CacheKey,
window: DailyBlockWindow,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn record_skip_insert<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn name(&self) -> &'static str;
}Expand description
Trait for block window cache backends
Implementations provide different storage strategies for caching block windows. All cache operations are async to support both in-memory and disk-based backends.
§Thread Safety
Implementations must be thread-safe and support concurrent access. Use interior
mutability (e.g., Mutex, RwLock) as needed.
§Error Handling
Cache operations should not fail the entire operation. If a cache read/write fails, implementations should log the error and continue (treating failures as cache misses).
Required Methods§
Sourcefn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
) -> Pin<Box<dyn Future<Output = Option<DailyBlockWindow>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
) -> Pin<Box<dyn Future<Output = Option<DailyBlockWindow>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieves a cached block window for the given key
Returns None if:
- The key is not in the cache
- The cached entry has expired (if TTL is enabled)
- A cache read error occurred (logged internally)
Sourcefn insert<'life0, 'async_trait>(
&'life0 self,
key: CacheKey,
window: DailyBlockWindow,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert<'life0, 'async_trait>(
&'life0 self,
key: CacheKey,
window: DailyBlockWindow,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Inserts a block window into the cache
If the cache has size limits and is full, this may evict older entries. Cache write errors are logged but do not cause failures.
§Returns
Returns Ok(()) if the entry was cached successfully, or Err if caching failed.
Callers should typically ignore errors (caching is best-effort).
Sourcefn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), BlockWindowError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clears all entries from the cache
Used for testing and cache management. Not all backends may support this.
Sourcefn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns current cache statistics
Statistics include hits, misses, evictions, and current size.
Sourcefn record_skip_insert<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn record_skip_insert<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Records a deliberate decision not to insert a window after a miss.
Currently invoked by
BlockWindowCalculator::get_daily_window when the requested
window touches or extends past the memoized chain tip — the
computed window is partial and the (chain, date) key cannot
disambiguate which head was current, so the insert is suppressed
even though the preceding get produced a miss. Implementations
increment CacheStats::skip_inserts so the count surfaces in
operator-facing metrics; backends that don’t track stats (e.g.
NoOpCache) may leave this as a no-op.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".