pub trait Storage {
// Required methods
fn lookup<'life0, 'life1, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_miss_handler<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<MissHandler>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn purge<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
purge_type: PurgeType,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn update_meta<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn as_any(&self) -> &(dyn Any + Send + Sync + 'static);
// Provided methods
fn lookup_streaming_write<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
_streaming_write_tag: Option<&'life1 [u8]>,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn expire<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn support_streaming_partial_write(&self) -> bool { ... }
}Expand description
Cache storage interface
Required Methods§
Sourcefn lookup<'life0, 'life1, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn lookup<'life0, 'life1, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Lookup the storage for the given CacheKey.
Sourcefn get_miss_handler<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<MissHandler>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_miss_handler<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<MissHandler>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Write the given CacheMeta to the storage. Return MissHandler to write the body later.
Sourcefn purge<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
purge_type: PurgeType,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn purge<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
purge_type: PurgeType,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete one cached entry for the given target.
PurgeTarget::Active asks storage to select one active entry for a logical cache key; it
does not request removal of every retained generation. PurgeTarget::Exact identifies the
exact entry to remove.
When resolving an active target, storage must return the storage-defined ID of the entry it
actually removed in PurgeOutcome::Purged. If HandleHit::entry_id or
HandleMiss::entry_id returns Some, an active purge outcome must contain that
CacheEntryId. Returning None would leave the identified entry tracked by the eviction
manager. Exact targets already contain the complete identity.
Sourcefn update_meta<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn update_meta<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
meta: &'life1 CacheMeta,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Update cache header and metadata for the already stored asset.
Provided Methods§
Sourcefn lookup_streaming_write<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
_streaming_write_tag: Option<&'life1 [u8]>,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn lookup_streaming_write<'life0, 'life1, 'life2, 'async_trait>(
&'static self,
key: &'life0 CacheKey,
_streaming_write_tag: Option<&'life1 [u8]>,
trace: &'life2 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheMeta, HitHandler)>>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Lookup the storage for the given CacheKey using a streaming write tag.
When streaming partial writes is supported, the request that initiates the write will also
pass an optional streaming_write_tag so that the storage may try to find the associated
HitHandler, for the same ongoing write.
Therefore, when the write tag is set, the storage implementation should either return a HitHandler that can be matched to that tag, or none at all. Otherwise when the storage supports concurrent streaming writes for the same key, the calling request may receive a different body from the one it expected.
By default this defers to the standard Storage::lookup implementation.
Sourcefn expire<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn expire<'life0, 'life1, 'async_trait>(
&'static self,
target: PurgeTarget<'life0>,
trace: &'life1 SpanHandle,
) -> Pin<Box<dyn Future<Output = Result<PurgeOutcome>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Mark one cached entry stale so it revalidates, keeping the entry stored.
Targets resolve the same way as Storage::purge. Once this returns
PurgeOutcome::Expired, the entry that was stored when the call ran must not be served
as a fresh hit, and its body should stay usable so a revalidation can reuse it on a 304.
Stale is not the same as unusable. Whether a reader is served the stale body while it revalidates is up to the entry’s serve stale windows, which this does not touch. How that is recorded is up to storage: rewriting the stored freshness and applying it on read both satisfy the contract.
This is deliberately not Storage::update_meta. That call needs a full CacheKey and
a CacheMeta the caller already holds from a hit, and a purge has neither. It would also
pin the recording strategy to rewriting the stored meta, turning this into a read modify
write that a concurrent revalidation can clobber.
The guarantee covers the stored entry, not a fill already in flight. A miss handler that
commits after this returns may replace the entry with a fresh one, which is the same race
Storage::purge has and is expected to be resolved by whatever serializes writes for
that key.
The default deletes the entry instead. Storage that cannot mark an entry stale must still
keep the next read from serving it, and deleting gives that guarantee at the cost of a
full refetch. It reports PurgeOutcome::Purged so the caller knows the entry is gone
and the eviction manager stops tracking it.
Sourcefn support_streaming_partial_write(&self) -> bool
fn support_streaming_partial_write(&self) -> bool
Whether this storage backend supports reading partially written data
This is to indicate when cache should unlock readers
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".