pub struct CacheControlConfig {
pub max_age: Option<u64>,
pub visibility: Option<CacheVisibility>,
pub no_cache: bool,
pub no_store: bool,
pub must_revalidate: bool,
pub immutable: bool,
}Expand description
Cache-Control 配置(对齐 nginx expires 指令)
对齐 nginx 配置:
expires 1h;→Cache-Control: max-age=3600expires -1;→Cache-Control: no-cacheexpires off;→ 不设置 Cache-Controladd_header Cache-Control "public";→Cache-Control: public
Fields§
§max_age: Option<u64>max-age(秒),None 表示不设置 max-age
visibility: Option<CacheVisibility>public(公共缓存,CDN 可缓存)/ private(仅浏览器缓存)/ None
no_cache: boolno-cache(必须重新验证)/ no-store(完全不缓存)
no_store: bool完全不缓存
must_revalidate: boolmust-revalidate(过期后必须重新验证)
immutable: boolimmutable(文件永不变化,浏览器可永久缓存,对齐前端构建工具指纹 hash 场景)
Implementations§
Source§impl CacheControlConfig
impl CacheControlConfig
Sourcepub fn with_max_age(self, seconds: u64) -> Self
pub fn with_max_age(self, seconds: u64) -> Self
设置 max-age(秒)
Sourcepub fn with_public(self) -> Self
pub fn with_public(self) -> Self
设置 public
Sourcepub fn with_private(self) -> Self
pub fn with_private(self) -> Self
设置 private
Sourcepub fn with_no_cache(self) -> Self
pub fn with_no_cache(self) -> Self
设置 no-cache(必须重新验证)
Sourcepub fn with_no_store(self) -> Self
pub fn with_no_store(self) -> Self
设置 no-store(完全不缓存)
Sourcepub fn with_must_revalidate(self) -> Self
pub fn with_must_revalidate(self) -> Self
设置 must-revalidate
Sourcepub fn with_immutable(self) -> Self
pub fn with_immutable(self) -> Self
设置 immutable(对齐前端构建工具指纹 hash 场景)
Sourcepub fn to_header_value(&self) -> Option<String>
pub fn to_header_value(&self) -> Option<String>
生成 Cache-Control 头值
返回 None 表示配置为空(不设置 Cache-Control 头)。
Trait Implementations§
Source§impl Clone for CacheControlConfig
impl Clone for CacheControlConfig
Source§fn clone(&self) -> CacheControlConfig
fn clone(&self) -> CacheControlConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheControlConfig
impl Debug for CacheControlConfig
Source§impl Default for CacheControlConfig
impl Default for CacheControlConfig
Source§fn default() -> CacheControlConfig
fn default() -> CacheControlConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CacheControlConfig
impl RefUnwindSafe for CacheControlConfig
impl Send for CacheControlConfig
impl Sync for CacheControlConfig
impl Unpin for CacheControlConfig
impl UnsafeUnpin for CacheControlConfig
impl UnwindSafe for CacheControlConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.