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: a layer applies only to the routes added before it, so routes added after it are not cached.
§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§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> Forget for ServerCacheLayer<M, K>
impl<M, K> Freeze for ServerCacheLayer<M, K>
impl<M, K> Move 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> UnsafeUnpin for ServerCacheLayer<M, K>where
M: UnsafeUnpin,
K: UnsafeUnpin,
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