HttpCache

Struct HttpCache 

Source
pub struct HttpCache<T>
where T: CacheManager,
{ pub mode: CacheMode, pub manager: T, pub options: HttpCacheOptions, }
Expand description

Caches requests according to http spec.

Fields§

§mode: CacheMode

Determines the manager behavior.

§manager: T

Manager instance that implements the CacheManager trait. By default, a manager implementation with cacache as the backend has been provided, see CACacheManager.

§options: HttpCacheOptions

Override the default cache options.

Implementations§

Source§

impl<T> HttpCache<T>
where T: CacheManager,

Source

pub fn can_cache_request( &self, middleware: &impl Middleware, ) -> Result<bool, Box<dyn Error + Sync + Send>>

Determines if the request should be cached

Source

pub async fn run_no_cache( &self, middleware: &mut impl Middleware, ) -> Result<(), Box<dyn Error + Sync + Send>>

Runs the actions to preform when the client middleware is running without the cache

Source

pub async fn run( &self, middleware: impl Middleware, ) -> Result<HttpResponse, Box<dyn Error + Sync + Send>>

Attempts to run the passed middleware along with the cache

Trait Implementations§

Source§

impl<T> Clone for HttpCache<T>
where T: Clone + CacheManager,

Source§

fn clone(&self) -> HttpCache<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for HttpCache<T>
where T: Debug + CacheManager,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> HttpCacheInterface for HttpCache<T>
where T: CacheManager,

Source§

fn analyze_request( &self, parts: &Parts, mode_override: Option<CacheMode>, ) -> Result<CacheAnalysis, Box<dyn Error + Sync + Send>>

Analyze a request to determine cache behavior
Source§

async fn lookup_cached_response( &self, key: &str, ) -> Result<Option<(HttpResponse, CachePolicy)>, Box<dyn Error + Sync + Send>>

Look up a cached response for the given cache key
Source§

async fn process_response( &self, analysis: CacheAnalysis, response: Response<Vec<u8>>, ) -> Result<Response<Vec<u8>>, Box<dyn Error + Sync + Send>>

Process a fresh response from upstream and potentially cache it
Source§

fn prepare_conditional_request( &self, parts: &mut Parts, _cached_response: &HttpResponse, policy: &CachePolicy, ) -> Result<(), Box<dyn Error + Sync + Send>>

Update request headers for conditional requests (e.g., If-None-Match)
Source§

async fn handle_not_modified( &self, cached_response: HttpResponse, fresh_parts: &Parts, ) -> Result<HttpResponse, Box<dyn Error + Sync + Send>>

Handle a 304 Not Modified response by returning the cached response

Auto Trait Implementations§

§

impl<T> Freeze for HttpCache<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for HttpCache<T>

§

impl<T> Send for HttpCache<T>

§

impl<T> Sync for HttpCache<T>

§

impl<T> Unpin for HttpCache<T>
where T: Unpin,

§

impl<T> !UnwindSafe for HttpCache<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,