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.
CacheLayer is cheaply Clone-able — clones share the same underlying
store, which lets you keep a handle for cache stats and invalidation while
the other clone is used as middleware.
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 size(&self) -> usize
pub fn size(&self) -> usize
Current number of entries in the store (including potentially expired ones that haven’t been purged yet).
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 Clone for CacheLayer
impl Clone for CacheLayer
Source§fn clone(&self) -> CacheLayer
fn clone(&self) -> CacheLayer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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