CachePolicy

Struct CachePolicy 

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

Runtime cache policy shared by the layer and backend.

Policies define how long responses stay in cache, which headers are persisted, which status codes are cacheable, and much more. Policies are cheap to clone and are immutable—the with_* builder helpers return new copies with the requested change.

Implementations§

Source§

impl CachePolicy

Source

pub fn new( ttl: Duration, negative_ttl: Duration, statuses: impl IntoIterator<Item = u16>, ) -> Self

Builds a new policy with explicit TTL settings and cacheable statuses.

Source

pub fn ttl_for(&self, status: StatusCode) -> Option<Duration>

Returns the TTL for the given HTTP status code if it should be cached.

Source

pub fn should_cache_method(&self, method: &Method) -> bool

Determines whether the request method is cacheable.

Source

pub fn respect_cache_control(&self) -> bool

Returns whether Cache-Control/Pragma headers on requests are honored.

Source

pub fn max_body_size(&self) -> Option<usize>

Source

pub fn min_body_size(&self) -> Option<usize>

Source

pub fn allow_streaming_bodies(&self) -> bool

Source

pub fn compression(&self) -> CompressionConfig

Source

pub fn refresh_before(&self) -> Duration

Source

pub fn ttl(&self) -> Duration

Source

pub fn negative_ttl(&self) -> Duration

Source

pub fn stale_while_revalidate(&self) -> Duration

Source

pub fn ml_logging(&self) -> &MLLoggingConfig

Source

pub fn tag_policy(&self) -> &TagPolicy

Source

pub fn streaming_policy(&self) -> &StreamingPolicy

Source

pub fn extract_tags(&self, method: &Method, uri: &Uri) -> Vec<String>

Extracts tags for a request using the configured tag extractor.

Source

pub fn headers_to_cache(&self, headers: &HeaderMap) -> Vec<(String, Vec<u8>)>

Returns the headers that should be cached based on the allowlist.

Source

pub fn with_ttl(self, ttl: Duration) -> Self

Source

pub fn with_negative_ttl(self, ttl: Duration) -> Self

Source

pub fn with_statuses(self, statuses: impl IntoIterator<Item = u16>) -> Self

Source

pub fn with_stale_while_revalidate(self, duration: Duration) -> Self

Source

pub fn with_refresh_before(self, duration: Duration) -> Self

Source

pub fn with_max_body_size(self, size: Option<usize>) -> Self

Source

pub fn with_min_body_size(self, size: Option<usize>) -> Self

Source

pub fn with_allow_streaming_bodies(self, allow: bool) -> Self

Source

pub fn with_compression(self, config: CompressionConfig) -> Self

Source

pub fn with_respect_cache_control(self, enabled: bool) -> Self

Source

pub fn with_method_predicate<F>(self, predicate: F) -> Self
where F: Fn(&Method) -> bool + Send + Sync + 'static,

Source

pub fn with_header_allowlist<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Source

pub fn with_ml_logging(self, config: MLLoggingConfig) -> Self

Source

pub fn with_tag_policy(self, policy: TagPolicy) -> Self

Source

pub fn with_tag_extractor<F>(self, extractor: F) -> Self
where F: Fn(&Method, &Uri) -> Vec<String> + Send + Sync + 'static,

Source

pub fn with_streaming_policy(self, policy: StreamingPolicy) -> Self

Trait Implementations§

Source§

impl Clone for CachePolicy

Source§

fn clone(&self) -> CachePolicy

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 Debug for CachePolicy

Source§

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

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

impl Default for CachePolicy

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, 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.