Cache redirects for 5 minutes in CDN and local

This commit is contained in:
Valentin Brandl 2019-08-07 21:26:12 +02:00
parent e81136b045
commit 312d9360c3
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
4 changed files with 19 additions and 6 deletions

View File

@ -1,3 +1,4 @@
use crate::statics::REDIRECT_AGE;
use std::{
collections::HashMap,
hash::Hash,
@ -17,7 +18,7 @@ where
pub(crate) fn new() -> Self {
Self {
cache: HashMap::new(),
duration: Duration::from_secs(5 * 60),
duration: REDIRECT_AGE,
}
}

View File

@ -21,7 +21,7 @@ use crate::{
data::{FilePath, State},
error::Result,
service::{Bitbucket, GitLab, Github, Service},
statics::{FAVICON, OPT},
statics::{FAVICON, OPT, REDIRECT_AGE},
};
use actix_files;
use actix_web::{
@ -80,7 +80,10 @@ fn redirect<T: Service>(
LOCATION,
T::redirect_url(&data.user, &data.repo, &head, &data.file).as_str(),
)
.set(CacheControl(vec![CacheDirective::Private]))
.set(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(REDIRECT_AGE.as_secs() as u32),
]))
.finish()
}));
}

View File

@ -108,7 +108,10 @@ pub(crate) trait Service: Sized {
)
.as_str(),
)
.set(CacheControl(vec![CacheDirective::Private]))
.set(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(REDIRECT_AGE.as_secs() as u32),
]))
.finish()
})
.from_err(),
@ -272,7 +275,12 @@ impl Service for GitLab {
)
.as_str(),
)
.set(CacheControl(vec![CacheDirective::Private]))
.set(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(
REDIRECT_AGE.as_secs() as u32
),
]))
.finish()
})
.from_err(),

View File

@ -1,8 +1,9 @@
use crate::{config::Opt, service::Github};
use std::env;
use std::{env, time::Duration};
use structopt::StructOpt;
const VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) const REDIRECT_AGE: Duration = Duration::from_secs(5 * 60);
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
lazy_static! {
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);