Cache icons on the client

This should make the vault pages load much faster, and massively reduce the number of requests.
This commit is contained in:
Jake Howard
2021-03-27 13:30:40 +00:00
parent 16eb0a56f9
commit b22564cb00
2 changed files with 17 additions and 10 deletions

View File

@ -92,17 +92,21 @@ impl Fairing for CORS {
}
}
pub struct Cached<R>(R, &'static str);
pub struct Cached<R>(R, String);
impl<R> Cached<R> {
pub const fn long(r: R) -> Cached<R> {
pub fn long(r: R) -> Cached<R> {
// 7 days
Self(r, "public, max-age=604800")
Self(r, String::from("public, max-age=604800"))
}
pub const fn short(r: R) -> Cached<R> {
pub fn short(r: R) -> Cached<R> {
// 10 minutes
Self(r, "public, max-age=600")
Self(r, String::from("public, max-age=600"))
}
pub fn ttl(r: R, ttl: u64) -> Cached<R> {
Self(r, format!("public, immutable, max-age={}", ttl))
}
}