Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
added CACHE_ENABLED envvar check
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Aug 11, 2020
1 parent 76f3d87 commit be8b163
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ async fn main() -> Result<()> {
crate::db::create_pool(&url, size, idle_size, timeout)
};

let authz_cache = var("CACHE_URL").ok().map(|url| {
let authz_cache = if let Some("1") = var("CACHE_ENABLED").ok().as_deref() {
let url = var("CACHE_URL").expect("CACHE_URL must be specified");

let size = var("CACHE_POOL_SIZE")
.map(|val| {
val.parse::<u32>()
Expand All @@ -60,8 +62,11 @@ async fn main() -> Result<()> {
})
.unwrap_or_else(|_| 300);

Cache::new(create_pool(&url, size, timeout), expiration_time)
});
let cache = Cache::new(create_pool(&url, size, timeout), expiration_time);
Some(cache)
} else {
None
};

app::run(&db, authz_cache).await
}
Expand Down

0 comments on commit be8b163

Please sign in to comment.