Skip to main content

RequestIssuer

Struct RequestIssuer 

Source
pub struct RequestIssuer { /* private fields */ }
Expand description

Identify cacheable requests by their URI.

§Caveats

The generated key is derived only from the request’s scheme, authority, path, query, and (optionally) method. It does not include content negotiation headers such as Accept-Encoding or Accept. If the cached responses vary by those headers — for example when a compression middleware also runs — a client may receive a representation encoded for a different request (e.g. a gzip body without Accept-Encoding: gzip).

The cache stores the response produced by the handlers inside it (hoops run outer-to-inner and the entry is captured on the way back out), so the negotiating middleware must run outside the cache — added to the router before the cache hoop — so it re-negotiates on every request, including cache hits. Alternatively, use a custom CacheIssuer that folds the relevant headers into the key.

Note that a Vary response header is not a fix here: the store never evaluates Vary at lookup time, so a Vary response is never cached (in either cache_private mode) — it would otherwise be replayed under the same key regardless of the request’s negotiation headers. Fold the relevant headers into a custom CacheIssuer key instead.

Implementations§

Source§

impl RequestIssuer

Source

pub fn new() -> Self

Create a new RequestIssuer.

Source

pub fn use_scheme(self, value: bool) -> Self

Whether to use the request’s URI scheme when generating the key.

Source

pub fn use_authority(self, value: bool) -> Self

Whether to use the request’s URI authority when generating the key.

Source

pub fn use_path(self, value: bool) -> Self

Whether to use the request’s URI path when generating the key.

Source

pub fn use_query(self, value: bool) -> Self

Whether to use the request’s URI query when generating the key.

Source

pub fn use_method(self, value: bool) -> Self

Whether to use the request method when generating the key.

Trait Implementations§

Source§

impl CacheIssuer for RequestIssuer

Source§

type Key = String

The key type used to identify a cached entry.
Source§

async fn issue(&self, req: &mut Request, _depot: &Depot) -> Option<Self::Key>

Issue a key for the request. If it returns None, the request will not be cached.
Source§

impl Clone for RequestIssuer

Source§

fn clone(&self) -> RequestIssuer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestIssuer

Source§

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

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

impl Default for RequestIssuer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more