Skip to main content

CacheControl

Struct CacheControl 

Source
pub struct CacheControl {
    pub directives: Vec<CacheDirective>,
}
Expand description

Parsed or constructed Cache-Control header.

§Examples

§Parsing

use armature_core::response_cache::CacheControl;

let cc = CacheControl::parse("public, max-age=3600, must-revalidate");
assert!(cc.is_public());
assert_eq!(cc.get_max_age(), Some(3600));

§Building

use armature_core::response_cache::CacheControl;
use std::time::Duration;

let cc = CacheControl::new()
    .private()
    .max_age(Duration::from_secs(300))
    .no_transform();

assert!(cc.is_private());

Fields§

§directives: Vec<CacheDirective>

All directives in this Cache-Control header

Implementations§

Source§

impl CacheControl

Source

pub fn new() -> Self

Create a new empty Cache-Control.

Source

pub fn parse(header: &str) -> Self

Parse a Cache-Control header value.

Source

pub fn to_header_value(&self) -> String

Convert to header value string.

Source

pub fn public(self) -> Self

Add the public directive.

Source

pub fn private(self) -> Self

Add the private directive.

Source

pub fn no_store(self) -> Self

Add the no-store directive.

Source

pub fn no_cache(self) -> Self

Add the no-cache directive.

Source

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

Add the max-age directive.

Source

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

Add the s-maxage directive for shared caches.

Source

pub fn must_revalidate(self) -> Self

Add the must-revalidate directive.

Source

pub fn proxy_revalidate(self) -> Self

Add the proxy-revalidate directive.

Source

pub fn no_transform(self) -> Self

Add the no-transform directive.

Source

pub fn immutable(self) -> Self

Add the immutable directive.

Source

pub fn directive(self, directive: CacheDirective) -> Self

Add a custom directive.

Source

pub fn is_public(&self) -> bool

Check if public directive is present.

Source

pub fn is_private(&self) -> bool

Check if private directive is present.

Source

pub fn is_no_store(&self) -> bool

Check if no-store directive is present.

Source

pub fn is_no_cache(&self) -> bool

Check if no-cache directive is present.

Source

pub fn is_must_revalidate(&self) -> bool

Check if must-revalidate directive is present.

Source

pub fn is_immutable(&self) -> bool

Check if immutable directive is present.

Source

pub fn get_max_age(&self) -> Option<u64>

Get the max-age value in seconds.

Source

pub fn get_s_maxage(&self) -> Option<u64>

Get the s-maxage value in seconds.

Source

pub fn is_cacheable(&self) -> bool

Check if the response is cacheable.

Source

pub fn freshness_lifetime(&self) -> Option<u64>

Get the freshness lifetime in seconds.

Returns s-maxage if present (for shared caches), otherwise max-age.

Source

pub fn never() -> Self

Create a “no-store” Cache-Control (never cache).

Source

pub fn public_max_age(duration: Duration) -> Self

Create a public cache with the given max-age.

Source

pub fn private_max_age(duration: Duration) -> Self

Create a private cache with the given max-age.

Source

pub fn immutable_asset(duration: Duration) -> Self

Create an immutable public cache (for versioned assets).

Source

pub fn revalidate(duration: Duration) -> Self

Create a must-revalidate cache.

Trait Implementations§

Source§

impl Clone for CacheControl

Source§

fn clone(&self) -> CacheControl

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 CacheControl

Source§

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

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

impl Default for CacheControl

Source§

fn default() -> CacheControl

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

impl Display for CacheControl

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<R, D> DepsPresent<D> for R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Injectable for T
where T: Send + Sync + 'static,

Source§

fn type_id_of() -> TypeId
where Self: Sized,

Returns the TypeId of this type (for internal use)
Source§

fn type_name_of() -> &'static str
where Self: Sized,

Returns the type name for debugging
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> Provider for T
where T: Injectable,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<R, D> VerifyDeps<D> for R

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