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
impl CachePolicy
Sourcepub fn new(
ttl: Duration,
negative_ttl: Duration,
statuses: impl IntoIterator<Item = u16>,
) -> Self
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.
Sourcepub fn ttl_for(&self, status: StatusCode) -> Option<Duration>
pub fn ttl_for(&self, status: StatusCode) -> Option<Duration>
Returns the TTL for the given HTTP status code if it should be cached.
Sourcepub fn should_cache_method(&self, method: &Method) -> bool
pub fn should_cache_method(&self, method: &Method) -> bool
Determines whether the request method is cacheable.
Sourcepub fn respect_cache_control(&self) -> bool
pub fn respect_cache_control(&self) -> bool
Returns whether Cache-Control/Pragma headers on requests are honored.
pub fn max_body_size(&self) -> Option<usize>
pub fn min_body_size(&self) -> Option<usize>
pub fn allow_streaming_bodies(&self) -> bool
pub fn compression(&self) -> CompressionConfig
pub fn refresh_before(&self) -> Duration
pub fn ttl(&self) -> Duration
pub fn negative_ttl(&self) -> Duration
pub fn stale_while_revalidate(&self) -> Duration
pub fn ml_logging(&self) -> &MLLoggingConfig
pub fn tag_policy(&self) -> &TagPolicy
pub fn streaming_policy(&self) -> &StreamingPolicy
Extracts tags for a request using the configured tag extractor.
Sourcepub fn headers_to_cache(&self, headers: &HeaderMap) -> Vec<(String, Vec<u8>)>
pub fn headers_to_cache(&self, headers: &HeaderMap) -> Vec<(String, Vec<u8>)>
Returns the headers that should be cached based on the allowlist.
pub fn with_ttl(self, ttl: Duration) -> Self
pub fn with_negative_ttl(self, ttl: Duration) -> Self
pub fn with_statuses(self, statuses: impl IntoIterator<Item = u16>) -> Self
pub fn with_stale_while_revalidate(self, duration: Duration) -> Self
pub fn with_refresh_before(self, duration: Duration) -> Self
pub fn with_max_body_size(self, size: Option<usize>) -> Self
pub fn with_min_body_size(self, size: Option<usize>) -> Self
pub fn with_allow_streaming_bodies(self, allow: bool) -> Self
pub fn with_compression(self, config: CompressionConfig) -> Self
pub fn with_respect_cache_control(self, enabled: bool) -> Self
pub fn with_method_predicate<F>(self, predicate: F) -> Self
pub fn with_header_allowlist<I, S>(self, headers: I) -> Self
pub fn with_ml_logging(self, config: MLLoggingConfig) -> Self
pub fn with_tag_policy(self, policy: TagPolicy) -> Self
pub fn with_tag_extractor<F>(self, extractor: F) -> Self
pub fn with_streaming_policy(self, policy: StreamingPolicy) -> Self
Trait Implementations§
Source§impl Clone for CachePolicy
impl Clone for CachePolicy
Source§fn clone(&self) -> CachePolicy
fn clone(&self) -> CachePolicy
Returns a duplicate of the value. Read more
1.0.0 · 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 CachePolicy
impl Debug for CachePolicy
Auto Trait Implementations§
impl Freeze for CachePolicy
impl !RefUnwindSafe for CachePolicy
impl Send for CachePolicy
impl Sync for CachePolicy
impl Unpin for CachePolicy
impl !UnwindSafe for CachePolicy
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