Cache redirects for 5 minutes in CDN and local
This commit is contained in:
parent
e81136b045
commit
312d9360c3
@ -1,3 +1,4 @@
|
|||||||
|
use crate::statics::REDIRECT_AGE;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
@ -17,7 +18,7 @@ where
|
|||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
cache: HashMap::new(),
|
cache: HashMap::new(),
|
||||||
duration: Duration::from_secs(5 * 60),
|
duration: REDIRECT_AGE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use crate::{
|
|||||||
data::{FilePath, State},
|
data::{FilePath, State},
|
||||||
error::Result,
|
error::Result,
|
||||||
service::{Bitbucket, GitLab, Github, Service},
|
service::{Bitbucket, GitLab, Github, Service},
|
||||||
statics::{FAVICON, OPT},
|
statics::{FAVICON, OPT, REDIRECT_AGE},
|
||||||
};
|
};
|
||||||
use actix_files;
|
use actix_files;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
@ -80,7 +80,10 @@ fn redirect<T: Service>(
|
|||||||
LOCATION,
|
LOCATION,
|
||||||
T::redirect_url(&data.user, &data.repo, &head, &data.file).as_str(),
|
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()
|
.finish()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,10 @@ pub(crate) trait Service: Sized {
|
|||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
)
|
)
|
||||||
.set(CacheControl(vec![CacheDirective::Private]))
|
.set(CacheControl(vec![
|
||||||
|
CacheDirective::Public,
|
||||||
|
CacheDirective::MaxAge(REDIRECT_AGE.as_secs() as u32),
|
||||||
|
]))
|
||||||
.finish()
|
.finish()
|
||||||
})
|
})
|
||||||
.from_err(),
|
.from_err(),
|
||||||
@ -272,7 +275,12 @@ impl Service for GitLab {
|
|||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
)
|
)
|
||||||
.set(CacheControl(vec![CacheDirective::Private]))
|
.set(CacheControl(vec![
|
||||||
|
CacheDirective::Public,
|
||||||
|
CacheDirective::MaxAge(
|
||||||
|
REDIRECT_AGE.as_secs() as u32
|
||||||
|
),
|
||||||
|
]))
|
||||||
.finish()
|
.finish()
|
||||||
})
|
})
|
||||||
.from_err(),
|
.from_err(),
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use crate::{config::Opt, service::Github};
|
use crate::{config::Opt, service::Github};
|
||||||
use std::env;
|
use std::{env, time::Duration};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
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");
|
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);
|
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);
|
||||||
|
Loading…
Reference in New Issue
Block a user