pub struct ServerCacheLayer<M, K = DefaultKeyer>where
M: CacheManager,
K: Keyer,{ /* private fields */ }Expand description
Tower layer for server-side HTTP response caching.
This layer should be placed AFTER routing to ensure request extensions (like path parameters) are preserved.
§Shared Cache Behavior
This implements a shared cache as defined in RFC 9111. Responses cached by this layer
are served to all users making requests with matching cache keys. The cache automatically
rejects responses with the private directive, but does not inspect Authorization headers
or session cookies.
For authenticated or user-specific endpoints, either:
- Set
Cache-Control: privatein responses (prevents caching) - Use a
CustomKeyerthat includes user/session identifiers in the cache key
Implementations§
Source§impl<M> ServerCacheLayer<M, DefaultKeyer>where
M: CacheManager,
impl<M> ServerCacheLayer<M, DefaultKeyer>where
M: CacheManager,
Source§impl<M, K> ServerCacheLayer<M, K>where
M: CacheManager,
K: Keyer,
impl<M, K> ServerCacheLayer<M, K>where
M: CacheManager,
K: Keyer,
Sourcepub fn with_keyer(manager: M, keyer: K) -> Self
pub fn with_keyer(manager: M, keyer: K) -> Self
Create a cache layer with a custom keyer.
Sourcepub fn with_options(self, options: ServerCacheOptions) -> Self
pub fn with_options(self, options: ServerCacheOptions) -> Self
Set custom options.
Sourcepub fn metrics(&self) -> &Arc<CacheMetrics>
pub fn metrics(&self) -> &Arc<CacheMetrics>
Get a reference to the cache metrics.
Trait Implementations§
Source§impl<M, K> Clone for ServerCacheLayer<M, K>
impl<M, K> Clone for ServerCacheLayer<M, K>
Source§fn clone(&self) -> ServerCacheLayer<M, K>
fn clone(&self) -> ServerCacheLayer<M, K>
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<S, M, K> Layer<S> for ServerCacheLayer<M, K>
impl<S, M, K> Layer<S> for ServerCacheLayer<M, K>
Auto Trait Implementations§
impl<M, K> Freeze for ServerCacheLayer<M, K>
impl<M, K> RefUnwindSafe for ServerCacheLayer<M, K>where
M: RefUnwindSafe,
K: RefUnwindSafe,
impl<M, K> Send for ServerCacheLayer<M, K>
impl<M, K> Sync for ServerCacheLayer<M, K>
impl<M, K> Unpin for ServerCacheLayer<M, K>
impl<M, K> UnwindSafe for ServerCacheLayer<M, K>where
M: UnwindSafe,
K: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more