mirror of https://github.com/spikecodes/libreddit
feat: add a feature flag to enable the cache
This commit is contained in:
parent
8435b8eab9
commit
023a2d8da9
|
@ -10,7 +10,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.11.1", default-features = false }
|
askama = { version = "0.11.1", default-features = false }
|
||||||
async-recursion = "1.0.0"
|
async-recursion = "1.0.0"
|
||||||
cached = "0.40.0"
|
cached = { version = "0.40.0", optional = true }
|
||||||
clap = { version = "4.0.18", default-features = false, features = ["std"] }
|
clap = { version = "4.0.18", default-features = false, features = ["std"] }
|
||||||
regex = "1.6.0"
|
regex = "1.6.0"
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
|
@ -25,3 +25,6 @@ tokio = { version = "1.21.2", features = ["full"] }
|
||||||
time = "0.3.16"
|
time = "0.3.16"
|
||||||
url = "2.3.1"
|
url = "2.3.1"
|
||||||
rust-embed = { version = "6.4.2", features = ["include-exclude"] }
|
rust-embed = { version = "6.4.2", features = ["include-exclude"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["cached"]
|
||||||
|
|
|
@ -112,7 +112,7 @@ fn request(url: String, quarantine: bool) -> Boxed<Result<Response<Body>, String
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a request to a Reddit API and parse the JSON response
|
// Make a request to a Reddit API and parse the JSON response
|
||||||
#[cached(size = 100, time = 30, result = true)]
|
#[cfg_attr(feature = "cached", cached(size = 100, time = 30, result = true))]
|
||||||
pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
|
||||||
// Build Reddit url from path
|
// Build Reddit url from path
|
||||||
let url = format!("https://www.reddit.com{}", path);
|
let url = format!("https://www.reddit.com{}", path);
|
||||||
|
|
Loading…
Reference in New Issue