pub trait CacheStorage:
Debug
+ Send
+ Sync
+ 'static {
type StoredEntry: StoredEntry;
type PutHandle: PutHandle;
// Required methods
fn get(
&self,
key: &CacheKey,
) -> impl Future<Output = Vec<Self::StoredEntry>> + Send;
fn put(
&self,
key: CacheKey,
policy: CachePolicy,
) -> impl Future<Output = Result<Self::PutHandle>> + Send;
fn invalidate(&self, key: &CacheKey) -> impl Future<Output = ()> + Send;
}Expand description
Storage backend for cached responses.
A key may carry multiple entries, one per Vary signature. get
returns the full list under a key; the cache handler picks among
them internally.
Writes are streaming — put returns a PutHandle that the
caller writes bytes into as they arrive. The handler signals end-of-
stream by calling PutHandle::finalize; dropping the handle
without finalizing aborts the write.
Required Associated Types§
Sourcetype StoredEntry: StoredEntry
type StoredEntry: StoredEntry
Concrete entry type returned by get.
Required Methods§
Sourcefn get(
&self,
key: &CacheKey,
) -> impl Future<Output = Vec<Self::StoredEntry>> + Send
fn get( &self, key: &CacheKey, ) -> impl Future<Output = Vec<Self::StoredEntry>> + Send
Fetch all entries stored under key. Returns an empty vec when
the key has no entries.
Sourcefn put(
&self,
key: CacheKey,
policy: CachePolicy,
) -> impl Future<Output = Result<Self::PutHandle>> + Send
fn put( &self, key: CacheKey, policy: CachePolicy, ) -> impl Future<Output = Result<Self::PutHandle>> + Send
Open a streaming insert for key with the supplied policy.
Returns a PutHandle that the caller writes body bytes into,
then closes with PutHandle::finalize. If an existing entry
has the same Vary signature, finalize replaces it; otherwise
the new entry is appended.
Returning Err aborts the cache write — the caller passes the
origin response through to the user but does not cache it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".