Skip to main content

shardline_cache/
store.rs

1use std::{future::Future, pin::Pin};
2
3use crate::{ReconstructionCacheError, ReconstructionCacheKey};
4
5/// Boxed asynchronous reconstruction-cache operation.
6pub type ReconstructionCacheFuture<'operation, T> =
7    Pin<Box<dyn Future<Output = Result<T, ReconstructionCacheError>> + Send + 'operation>>;
8
9/// Asynchronous reconstruction-cache adapter contract.
10pub trait AsyncReconstructionCache: Send + Sync {
11    /// Verifies that the adapter is configured correctly and can serve requests.
12    fn ready(&self) -> ReconstructionCacheFuture<'_, ()>;
13
14    /// Loads one cached reconstruction payload.
15    fn get<'operation>(
16        &'operation self,
17        key: &'operation ReconstructionCacheKey,
18    ) -> ReconstructionCacheFuture<'operation, Option<Vec<u8>>>;
19
20    /// Stores one reconstruction payload.
21    fn put<'operation>(
22        &'operation self,
23        key: &'operation ReconstructionCacheKey,
24        payload: &'operation [u8],
25    ) -> ReconstructionCacheFuture<'operation, ()>;
26
27    /// Deletes one cached reconstruction payload.
28    fn delete<'operation>(
29        &'operation self,
30        key: &'operation ReconstructionCacheKey,
31    ) -> ReconstructionCacheFuture<'operation, bool>;
32}