pub struct CacheControlBuilder { /* private fields */ }Expand description
Builder for constructing Cache-Control header values.
Provides a fluent API for building complex cache control policies.
§Example
use fastapi_core::middleware::CacheControlBuilder;
// Public, cacheable for 1 hour, must revalidate after
let cache = CacheControlBuilder::new()
.public()
.max_age_secs(3600)
.must_revalidate()
.build();
// Private, no caching
let no_cache = CacheControlBuilder::new()
.private()
.no_store()
.build();
// CDN-friendly: public with different browser/CDN TTLs
let cdn = CacheControlBuilder::new()
.public()
.max_age_secs(60) // Browser caches for 1 minute
.s_maxage_secs(3600) // CDN caches for 1 hour
.build();Implementations§
Source§impl CacheControlBuilder
impl CacheControlBuilder
Sourcepub fn private(self) -> Self
pub fn private(self) -> Self
Add the private directive - response may only be cached by browser.
Sourcepub fn no_transform(self) -> Self
pub fn no_transform(self) -> Self
Add the no-transform directive - caches must not modify response.
Sourcepub fn must_revalidate(self) -> Self
pub fn must_revalidate(self) -> Self
Add the must-revalidate directive - cache must check origin when stale.
Sourcepub fn proxy_revalidate(self) -> Self
pub fn proxy_revalidate(self) -> Self
Add the proxy-revalidate directive - shared caches must check origin when stale.
Sourcepub fn immutable(self) -> Self
pub fn immutable(self) -> Self
Add the immutable directive - response won’t change during freshness lifetime.
Sourcepub fn max_age_secs(self, seconds: u32) -> Self
pub fn max_age_secs(self, seconds: u32) -> Self
Set max-age directive - maximum time response is fresh (in seconds).
Sourcepub fn s_maxage_secs(self, seconds: u32) -> Self
pub fn s_maxage_secs(self, seconds: u32) -> Self
Set s-maxage directive - maximum time for shared caches (in seconds).
Sourcepub fn stale_while_revalidate_secs(self, seconds: u32) -> Self
pub fn stale_while_revalidate_secs(self, seconds: u32) -> Self
Set stale-while-revalidate directive - serve stale while revalidating (in seconds).
Sourcepub fn stale_if_error_secs(self, seconds: u32) -> Self
pub fn stale_if_error_secs(self, seconds: u32) -> Self
Set stale-if-error directive - serve stale if origin errors (in seconds).
Sourcepub fn is_no_cache(&self) -> bool
pub fn is_no_cache(&self) -> bool
Check if this represents a no-cache policy.
Trait Implementations§
Source§impl Clone for CacheControlBuilder
impl Clone for CacheControlBuilder
Source§fn clone(&self) -> CacheControlBuilder
fn clone(&self) -> CacheControlBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more