Skip to content

Commit

Permalink
fix(project-wide): fixed cargo errors caused by merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TadoTheMiner committed Mar 19, 2024
1 parent 5ec0e8c commit b137ee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fs, time::SystemTime};

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
struct CacheEntry {
content: String,
created: SystemTime,
}

pub fn add_cache(url: String, result: String) -> Result<(), Error> {
let mut cache = read_cache_file();
pub fn add_cache(url: String, result: String) -> Result<()> {
let mut cache = read_cache_file()?;

cache.insert(
url,
Expand All @@ -24,11 +25,11 @@ pub fn add_cache(url: String, result: String) -> Result<(), Error> {
}

#[allow(unused_must_use)]
pub fn get_from_cache(url: &String) -> Result<Option<String>> {
pub fn get_from_cache(url: &String, cache_lifetime_seconds: u64) -> Result<Option<String>> {
let mut cache = read_cache_file()?;
if let Some(entry) = cache.get(url) {
if SystemTime::now().duration_since(entry.created).unwrap()
<= std::time::Duration::from_secs(CACHE_LIFETIME_SECONDS)
<= std::time::Duration::from_secs(cache_lifetime_seconds)
{
return Ok(Some(entry.content.clone()));
}
Expand Down Expand Up @@ -59,6 +60,5 @@ fn write_to_cache(cache: HashMap<String, CacheEntry>) -> Result<()> {
Ok(fs::write(
get_cachefile_path(),
serde_json::to_string(&cache)?,

)?)
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mod error;

use config::Config;

pub type Result<T> = std::result::Result<T, error::Error>;

#[derive(serde::Deserialize)]
#[serde(untagged)]
enum ApiResult {
Expand Down

0 comments on commit b137ee7

Please sign in to comment.