pub trait CachePolicy:
Default
+ Clone
+ Send
+ Sync
+ 'static {
type Store: CacheStore + Send + Sync + 'static;
// Provided methods
fn cache_key(
&self,
ctx: &RequestContext,
req: &Request<Body>,
) -> Option<String> { ... }
fn ttl_seconds(&self) -> Option<u64> { ... }
fn should_cache_response(&self, response: &Response) -> bool { ... }
}Expand description
Required Associated Types§
Sourcetype Store: CacheStore + Send + Sync + 'static
type Store: CacheStore + Send + Sync + 'static
The cache store type used by this policy
Provided Methods§
Sourcefn cache_key(&self, ctx: &RequestContext, req: &Request<Body>) -> Option<String>
fn cache_key(&self, ctx: &RequestContext, req: &Request<Body>) -> Option<String>
Generates a cache key for the given request.
Return None to skip caching for this request.
Default implementation caches all GET requests.
Sourcefn ttl_seconds(&self) -> Option<u64>
fn ttl_seconds(&self) -> Option<u64>
Returns the time-to-live in seconds for cached responses.
Return None for no expiration.
Sourcefn should_cache_response(&self, response: &Response) -> bool
fn should_cache_response(&self, response: &Response) -> bool
Determines whether a response should be cached.
Default implementation caches only 200 OK responses.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.