Skip to main content

CacheControl

Struct CacheControl 

Source
#[non_exhaustive]
pub struct CacheControl {
Show 15 fields pub public: bool, pub private: bool, pub no_cache: bool, pub no_store: bool, pub no_transform: bool, pub must_revalidate: bool, pub proxy_revalidate: bool, pub immutable: bool, pub max_age: Option<u64>, pub s_maxage: Option<u64>, pub stale_while_revalidate: Option<u64>, pub stale_if_error: Option<u64>, pub only_if_cached: bool, pub max_stale: Option<u64>, pub min_fresh: Option<u64>,
}
Expand description

Structured Cache-Control header (RFC 7234 §5.2).

All boolean directives default to false; numeric directives default to None (absent). Use the builder methods to set them.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§public: bool

public — response may be stored by any cache.

§private: bool

private — response is intended for a single user; must not be stored by a shared cache.

§no_cache: bool

no-cache — cache must revalidate with the origin before serving.

§no_store: bool

no-store — must not store any part of the request or response.

§no_transform: bool

no-transform — no transformations or conversions should be made.

§must_revalidate: bool

must-revalidate — stale responses must not be used without revalidation.

§proxy_revalidate: bool

proxy-revalidate — like must-revalidate but only for shared caches.

§immutable: bool

immutable — response body will not change over its lifetime.

§max_age: Option<u64>

max-age=<seconds> — maximum time the response is considered fresh.

§s_maxage: Option<u64>

s-maxage=<seconds> — overrides max-age for shared caches.

§stale_while_revalidate: Option<u64>

stale-while-revalidate=<seconds> — serve stale while revalidating.

§stale_if_error: Option<u64>

stale-if-error=<seconds> — use stale response on error.

§only_if_cached: bool

only-if-cached — do not use the network; only return a cached response.

§max_stale: Option<u64>

max-stale[=<seconds>] — accept a response up to this many seconds stale. Some(0) means any staleness is acceptable; None means the directive is absent.

§min_fresh: Option<u64>

min-fresh=<seconds> — require at least this much remaining freshness.

Implementations§

Source§

impl CacheControl

Source

pub fn new() -> Self

Create an empty CacheControl with all directives absent.

Source

pub fn public(self) -> Self

Set the public directive.

Source

pub fn private(self) -> Self

Set the private directive.

Source

pub fn no_cache(self) -> Self

Set the no-cache directive.

Source

pub fn no_store(self) -> Self

Set the no-store directive.

Source

pub fn no_transform(self) -> Self

Set the no-transform directive.

Source

pub fn must_revalidate(self) -> Self

Set the must-revalidate directive.

Source

pub fn proxy_revalidate(self) -> Self

Set the proxy-revalidate directive.

Source

pub fn immutable(self) -> Self

Set the immutable directive.

Source

pub fn max_age(self, seconds: u64) -> Self

Set max-age=<seconds>.

Source

pub fn s_maxage(self, seconds: u64) -> Self

Set s-maxage=<seconds>.

Source

pub fn stale_while_revalidate(self, seconds: u64) -> Self

Set stale-while-revalidate=<seconds>.

Source

pub fn stale_if_error(self, seconds: u64) -> Self

Set stale-if-error=<seconds>.

Source

pub fn only_if_cached(self) -> Self

Set the only-if-cached directive.

Source

pub fn max_stale(self, seconds: u64) -> Self

Set max-stale[=<seconds>]. Pass 0 to accept any staleness.

Source

pub fn min_fresh(self, seconds: u64) -> Self

Set min-fresh=<seconds>.

Source

pub fn no_caching() -> Self

Convenience: no-store (disable all caching).

use api_bones::cache::CacheControl;

let cc = CacheControl::no_caching();
assert!(cc.no_store);
assert_eq!(cc.to_string(), "no-store");
Source

pub fn private_no_cache() -> Self

Convenience: private, no-cache, no-store.

use api_bones::cache::CacheControl;

let cc = CacheControl::private_no_cache();
assert!(cc.private && cc.no_cache && cc.no_store);

Trait Implementations§

Source§

impl Clone for CacheControl

Source§

fn clone(&self) -> CacheControl

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 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<'de> Deserialize<'de> for CacheControl

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for CacheControl

Source§

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

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

impl FromStr for CacheControl

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a Cache-Control header value.

Unknown directives are silently ignored, matching real-world HTTP caching behaviour.

use api_bones::cache::CacheControl;

let cc: CacheControl = "public, max-age=3600, must-revalidate".parse().unwrap();
assert!(cc.public);
assert_eq!(cc.max_age, Some(3600));
assert!(cc.must_revalidate);
Source§

type Err = ParseCacheControlError

The associated error which can be returned from parsing.
Source§

impl PartialEq for CacheControl

Source§

fn eq(&self, other: &CacheControl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CacheControl

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for CacheControl

Source§

impl StructuralPartialEq for CacheControl

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> 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<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,