@@ -38,10 +38,11 @@ mod gist;
38
38
mod sandbox;
39
39
40
40
const ONE_HOUR_IN_SECONDS : u32 = 60 * 60 ;
41
- const ONE_DAY_IN_SECONDS : u64 = 60 * 60 * 24 ;
42
- const ONE_YEAR_IN_SECONDS : u64 = 60 * 60 * 24 * 365 ;
41
+ const ONE_HOUR : Duration = Duration :: from_secs ( ONE_HOUR_IN_SECONDS as u64 ) ;
42
+ const ONE_DAY : Duration = Duration :: from_secs ( 60 * 60 * 24 ) ;
43
+ const ONE_YEAR : Duration = Duration :: from_secs ( 60 * 60 * 24 * 365 ) ;
43
44
44
- const SANDBOX_CACHE_TIME_TO_LIVE_IN_SECONDS : u64 = ONE_HOUR_IN_SECONDS as u64 ;
45
+ const SANDBOX_CACHE_TIME_TO_LIVE : Duration = ONE_HOUR ;
45
46
46
47
fn main ( ) {
47
48
// Dotenv may be unable to load environment variables, but that's ok in production
@@ -66,11 +67,9 @@ fn main() {
66
67
67
68
let files = Staticfile :: new ( & root) . expect ( "Unable to open root directory" ) ;
68
69
let mut files = Chain :: new ( files) ;
69
- let one_day = Duration :: new ( ONE_DAY_IN_SECONDS , 0 ) ;
70
- let one_year = Duration :: new ( ONE_YEAR_IN_SECONDS , 0 ) ;
71
70
72
- files. link_after ( ModifyWith :: new ( Cache :: new ( one_day ) ) ) ;
73
- files. link_after ( Prefix :: new ( & [ "assets" ] , Cache :: new ( one_year ) ) ) ;
71
+ files. link_after ( ModifyWith :: new ( Cache :: new ( ONE_DAY ) ) ) ;
72
+ files. link_after ( Prefix :: new ( & [ "assets" ] , Cache :: new ( ONE_YEAR ) ) ) ;
74
73
files. link_after ( GuessContentType :: new ( ContentType :: html ( ) . 0 ) ) ;
75
74
76
75
let mut gist_router = Router :: new ( ) ;
@@ -436,9 +435,7 @@ where
436
435
437
436
match cache. clone ( ) {
438
437
Some ( cached) => {
439
- if cached. time . elapsed ( )
440
- > Duration :: from_secs ( SANDBOX_CACHE_TIME_TO_LIVE_IN_SECONDS )
441
- {
438
+ if cached. time . elapsed ( ) > SANDBOX_CACHE_TIME_TO_LIVE {
442
439
SandboxCacheOne :: populate ( & mut * cache, populator)
443
440
} else {
444
441
Ok ( cached. value )
0 commit comments