diff --git a/Cargo.lock b/Cargo.lock index 7f41e16..cbbc2e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1037,6 +1037,36 @@ dependencies = [ "slab", ] +[[package]] +name = "gabrielsimmerdotcom" +version = "0.1.0" +dependencies = [ + "async-trait", + "axum", + "clap 4.3.21", + "comrak", + "crossbeam", + "file-format", + "frontmatter", + "futures", + "hex", + "hyper", + "maud", + "orgize", + "prost", + "prost-build", + "rand", + "rss", + "serde", + "serde_dhall", + "sha2", + "sqlx", + "time", + "tokio", + "tower", + "tower-http", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -2007,37 +2037,6 @@ dependencies = [ "prost", ] -[[package]] -name = "quick-start" -version = "0.1.0" -dependencies = [ - "async-trait", - "axum", - "clap 4.3.21", - "comrak", - "crossbeam", - "file-format", - "frontmatter", - "futures", - "hex", - "hyper", - "lazy_static 1.4.0", - "maud", - "orgize", - "prost", - "prost-build", - "rand", - "rss", - "serde", - "serde_dhall", - "sha2", - "sqlx", - "time", - "tokio", - "tower", - "tower-http", -] - [[package]] name = "quick-xml" version = "0.30.0" diff --git a/Cargo.toml b/Cargo.toml index 2097297..4f2e191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ hyper = { version = "0.14", features = ["full"] } tower-http = { version = "0.4.1", features = ["fs", "add-extension", "auth", "compression-full", "trace"] } sha2 = "0.10.7" hex = "0.4" -lazy_static = "1.4.0" futures = "0.3.28" comrak = "0.1" orgize = { git = "https://git.gmem.ca/arch/orgize.git", branch = "org-images" } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index b99e3a3..fecd5ae 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -1,12 +1,6 @@ -use async_trait::async_trait; use sqlx::FromRow; -use std::{ - fmt, - time::{SystemTime, UNIX_EPOCH}, -}; - +use std::sync::{OnceLock, Mutex}; use std::collections::HashMap; -use tokio::sync::Mutex; #[derive(Clone, Debug, FromRow)] pub struct CachedItem { @@ -16,7 +10,7 @@ pub struct CachedItem { } /// Determine whether we should actually use the cached item or not. -fn should_use(item: &CachedItem) -> bool { +fn should_use(_item: &CachedItem) -> bool { // let current_time: i64 = SystemTime::now() // .duration_since(UNIX_EPOCH) // .expect("SystemTime before UNIX EPOCH!") @@ -28,12 +22,10 @@ fn should_use(item: &CachedItem) -> bool { true } -lazy_static! { - static ref CACHE: Mutex> = Mutex::new(HashMap::new()); -} +static CACHE: OnceLock>> = OnceLock::new(); pub async fn get(key: &String) -> Option { - let data = CACHE.lock().await; + let data = CACHE.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); dbg!(&key); match data.get(key) { Some(c) => { @@ -48,12 +40,13 @@ pub async fn get(key: &String) -> Option { } } -async fn rm(key: String) { - let mut data = CACHE.lock().await; - data.remove(&key); -} +// async fn rm(key: String) { +// let mut data = CACHE.get().unwrap().clone(); +// data.remove(&key); +// let _ = CACHE.set(data); +// } pub async fn set(key: String, item: CachedItem) { - let mut data = CACHE.lock().await; + let mut data = CACHE.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); data.insert(key, item); } diff --git a/src/main.rs b/src/main.rs index df0e8a3..ceff837 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,3 @@ -#[macro_use] -extern crate lazy_static; - // Include the `items` module, which is generated from items.proto. pub mod items { include!(concat!(env!("OUT_DIR"), "/gabrielsimmerdotcom.gossip.rs"));