pub struct CacheLayer { /* private fields */ }Expand description
An in-memory response cache middleware.
Construct with CacheLayer::memory and configure with the builder methods
ttl and vary_by_header.
Implementations§
Source§impl CacheLayer
impl CacheLayer
Sourcepub fn memory(capacity: usize) -> Self
pub fn memory(capacity: usize) -> Self
Create a new in-memory cache bounded to capacity entries.
Default TTL is 60 seconds. Adjust with .ttl().
Sourcepub fn vary_by_header(self, name: &str) -> Self
pub fn vary_by_header(self, name: &str) -> Self
Include a request header in the cache key so that different values of that header produce separate cache entries.
Header name matching is case-insensitive. Call multiple times to vary by more than one header.
use rust_web_server::cache::CacheLayer;
let layer = CacheLayer::memory(500)
.vary_by_header("Accept")
.vary_by_header("Accept-Language");Trait Implementations§
Source§impl Middleware for CacheLayer
impl Middleware for CacheLayer
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Auto Trait Implementations§
impl !Freeze for CacheLayer
impl RefUnwindSafe for CacheLayer
impl Send for CacheLayer
impl Sync for CacheLayer
impl Unpin for CacheLayer
impl UnsafeUnpin for CacheLayer
impl UnwindSafe for CacheLayer
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