Skip to content

Commit

Permalink
feat: support moka in-memory cache
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Jun 2, 2023
1 parent 778a4c7 commit 65f17ba
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 16 deletions.
168 changes: 167 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async-compression = { version = "0.4.0", features = ["tokio", "gzip"] }
async-trait = "0.1.68"
base64 = "0.21.0"
clap = { version = "4.2.7", features = ["derive", "string"] }
http-cache-reqwest = "0.9.0"
http-cache-reqwest = { version = "0.9.0", features = ["manager-cacache", "manager-moka"] }
jsonwebtoken = "8.3.0"
reqwest = { version = "0.11.18", default-features = false, features = ["rustls", "tokio-rustls", "json"] }
reqwest-middleware = "0.2.2"
Expand Down
24 changes: 10 additions & 14 deletions src/judger/io_fast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Input, Judger, Output};
use async_trait::async_trait;
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache};
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, MokaManager};
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -59,32 +59,26 @@ impl Judger for FastIOJudgeSpec {

match env::var("REMOTE_INPUT_CACHE") {
Ok(val) => match val.as_str() {
"true" | "1" => {
"true" | "1" | "cacache" => {
client = client.with(Cache(HttpCache {
mode: CacheMode::Default,
manager: CACacheManager::default(),
options: None,
}));
}
"false" | "0" => {
"mem" | "moka" => {
client = client.with(Cache(HttpCache {
mode: CacheMode::NoStore,
manager: CACacheManager::default(),
options: None,
}));
}
_ => {
client = client.with(Cache(HttpCache {
mode: CacheMode::NoStore,
manager: CACacheManager::default(),
mode: CacheMode::Default,
manager: MokaManager::default(),
options: None,
}));
}
_ => {}
},
Err(_) => {
client = client.with(Cache(HttpCache {
mode: CacheMode::NoStore,
manager: CACacheManager::default(),
mode: CacheMode::Default,
manager: MokaManager::default(),
options: None,
}));
}
Expand All @@ -97,6 +91,7 @@ impl Judger for FastIOJudgeSpec {
req = req.header("Authorization", format!("Bearer {}", auth));
}

info!("Fetching input from {}", input_url);
let res = req
.send()
.await
Expand All @@ -106,6 +101,7 @@ impl Judger for FastIOJudgeSpec {
.text()
.await
.map_err(|e| format!("Error reading input: {}", e))?;
info!("Fetched input from {}", input_url);

return Ok(Input { stdin: input });
}
Expand Down

0 comments on commit 65f17ba

Please sign in to comment.