pub struct Cache<S: CacheStorage> { /* private fields */ }Expand description
Cache handler. Mount on a trillium_client::Client together with
a CacheStorage backend.
Cache is cheap to Clone: storage is held in an Arc, so clones
share the same backend.
Implementations§
Source§impl<S: CacheStorage> Cache<S>
impl<S: CacheStorage> Cache<S>
Sourcepub fn new(storage: S) -> Self
pub fn new(storage: S) -> Self
Construct a cache handler with default options
(CacheOptions::default) and a 16 MiB body-size cap.
Sourcepub fn with_options(self, options: CacheOptions) -> Self
pub fn with_options(self, options: CacheOptions) -> Self
Replace the cache options.
Mark this cache as a shared cache (proxy/CDN). Equivalent to
with_options with shared: true.
Sourcepub fn with_max_cacheable_size(self, max: u64) -> Self
pub fn with_max_cacheable_size(self, max: u64) -> Self
Set the cap on response body bytes the cache will store. Responses larger than this pass through but are not stored. If the cap is exceeded mid-stream, the cache write is aborted and the remainder of the body passes through unmodified.
Trait Implementations§
Source§impl<S: CacheStorage> ClientHandler for Cache<S>
impl<S: CacheStorage> ClientHandler for Cache<S>
Source§async fn run(&self, conn: &mut Conn) -> Result<()>
async fn run(&self, conn: &mut Conn) -> Result<()>
Forward-pass hook, called before the network round-trip in declared order. Read more
Source§impl<S: CacheStorage> Clone for Cache<S>
impl<S: CacheStorage> Clone for Cache<S>
Auto Trait Implementations§
impl<S> Freeze for Cache<S>
impl<S> RefUnwindSafe for Cache<S>where
S: RefUnwindSafe,
impl<S> Send for Cache<S>
impl<S> Sync for Cache<S>
impl<S> Unpin for Cache<S>
impl<S> UnsafeUnpin for Cache<S>
impl<S> UnwindSafe for Cache<S>where
S: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more