pub struct Caching { /* private fields */ }
Available on crate feature
fs
only.Expand description
Controls if caching information should be sent.
The Caching struct contains an Etag which stores a random tag which indentifies a specific file. The Etag gets generated when the struct gets created.
§Example
ⓘ
use fire::{get, Request};
use fire::fs::Caching;
use fire::into::IntoResponse;
use std::cell::LazyCell;
const INDEX_CACHE: LazyCell<Caching> = LazyCell::new(|| {
Caching::default()
});
#[get("/")]
fn index(req: &mut Request) -> Response {
let cache = INDEX_CACHE.clone();
if cache.if_none_match(req.header()) {
return cache.into_response()
}
let mut resp = Response::html("<h1>Hello, World!</h1>");
cache.complete_header(&mut resp.header);
resp
}
Implementations§
Source§impl Caching
impl Caching
pub fn new(max_age: Duration) -> Self
pub fn default() -> Self
pub fn if_none_match(&self, header: &RequestHeader) -> bool
pub fn complete_header(self, header: &mut ResponseHeader)
Trait Implementations§
Source§impl IntoResponse for Caching
impl IntoResponse for Caching
fn into_response(self) -> Response
impl Eq for Caching
impl StructuralPartialEq for Caching
Auto Trait Implementations§
impl Freeze for Caching
impl RefUnwindSafe for Caching
impl Send for Caching
impl Sync for Caching
impl Unpin for Caching
impl UnwindSafe for Caching
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.