pingora_cache::storage

Trait Storage

Source
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,
        key: &'life0 CompactCacheKey,
        purge_type: PurgeType,
        trace: &'life1 SpanHandle,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + 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 support_streaming_partial_write(&self) -> bool { ... }
}
Expand description

Cache storage interface

Required Methods§

Source

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.

Source

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.

Source

fn purge<'life0, 'life1, 'async_trait>( &'static self, key: &'life0 CompactCacheKey, purge_type: PurgeType, trace: &'life1 SpanHandle, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete the cached asset for the given key

CompactCacheKey is used here because it is how eviction managers store the keys

Source

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.

Source

fn as_any(&self) -> &(dyn Any + Send + Sync + 'static)

Helper function to cast the trait object to concrete types

Provided Methods§

Source

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.

Source

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

Implementors§