From cbd55399db69341e248482ae9e7260fc910bb586 Mon Sep 17 00:00:00 2001 From: Orual Date: Tue, 18 Nov 2025 09:23:04 -0500 Subject: [PATCH] modified vendored cache impl --- Cargo.lock | 8 +- crates/jacquard-identity/src/lib.rs | 93 ++++++++++--------- crates/jacquard-oauth/src/resolver.rs | 1 + crates/mini-moka-vendored/src/common.rs | 2 +- .../src/common/concurrent/housekeeper.rs | 7 +- crates/mini-moka-vendored/src/common/time.rs | 6 +- crates/mini-moka-vendored/src/lib.rs | 2 + .../mini-moka-vendored/src/sync/base_cache.rs | 3 +- crates/mini-moka-vendored/src/sync/builder.rs | 3 +- crates/mini-moka-vendored/src/sync/cache.rs | 2 +- examples/app_password_create_post.rs | 2 +- 11 files changed, 66 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c4bcfa5..e7113c6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2262,7 +2262,7 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jacquard" -version = "0.9.3" +version = "0.9.4" dependencies = [ "bytes", "clap", @@ -2389,7 +2389,7 @@ dependencies = [ [[package]] name = "jacquard-derive" -version = "0.9.3" +version = "0.9.4" dependencies = [ "heck 0.5.0", "inventory", @@ -2432,7 +2432,7 @@ dependencies = [ [[package]] name = "jacquard-lexgen" -version = "0.9.3" +version = "0.9.4" dependencies = [ "clap", "clap_complete", @@ -2519,7 +2519,7 @@ dependencies = [ [[package]] name = "jacquard-repo" -version = "0.9.3" +version = "0.9.4" dependencies = [ "anyhow", "bytes", diff --git a/crates/jacquard-identity/src/lib.rs b/crates/jacquard-identity/src/lib.rs index 4cbc26d2..e76d2a43 100644 --- a/crates/jacquard-identity/src/lib.rs +++ b/crates/jacquard-identity/src/lib.rs @@ -100,7 +100,7 @@ use { use { crate::lexicon_resolver::ResolvedLexiconSchema, jacquard_common::{smol_str::SmolStr, types::string::Nsid}, - std::time::Duration, + mini_moka::time::Duration, }; #[cfg(all( @@ -110,7 +110,8 @@ use { use std::sync::Arc; // Platform-specific cache implementations -#[cfg(all(feature = "cache", not(target_arch = "wasm32")))] +//#[cfg(all(feature = "cache", not(target_arch = "wasm32")))] +#[cfg(feature = "cache")] mod cache_impl { /// Native: Use sync cache (thread-safe, no mutex needed) pub type Cache = mini_moka::sync::Cache; @@ -151,50 +152,50 @@ mod cache_impl { } } -#[cfg(all(feature = "cache", target_arch = "wasm32"))] -mod cache_impl { - use std::sync::{Arc, Mutex}; - - /// WASM: Use unsync cache in Arc> (no threads, but need interior mutability) - pub type Cache = Arc>>; - - pub fn new_cache(max_capacity: u64, ttl: std::time::Duration) -> Cache - where - K: std::hash::Hash + Eq + 'static, - V: Clone + 'static, - { - Arc::new(Mutex::new( - mini_moka::unsync::Cache::builder() - .max_capacity(max_capacity) - .time_to_idle(ttl) - .build(), - )) - } - - pub fn get(cache: &Cache, key: &K) -> Option - where - K: std::hash::Hash + Eq + 'static, - V: Clone + 'static, - { - cache.lock().unwrap().get(key).cloned() - } - - pub fn insert(cache: &Cache, key: K, value: V) - where - K: std::hash::Hash + Eq + 'static, - V: Clone + 'static, - { - cache.lock().unwrap().insert(key, value); - } - - pub fn invalidate(cache: &Cache, key: &K) - where - K: std::hash::Hash + Eq + 'static, - V: Clone + 'static, - { - cache.lock().unwrap().invalidate(key); - } -} +// #[cfg(all(feature = "cache", target_arch = "wasm32"))] +// mod cache_impl { +// use std::sync::{Arc, Mutex}; + +// /// WASM: Use unsync cache in Arc> (no threads, but need interior mutability) +// pub type Cache = Arc>>; + +// pub fn new_cache(max_capacity: u64, ttl: std::time::Duration) -> Cache +// where +// K: std::hash::Hash + Eq + 'static, +// V: Clone + 'static, +// { +// Arc::new(Mutex::new( +// mini_moka::unsync::Cache::builder() +// .max_capacity(max_capacity) +// .time_to_idle(ttl) +// .build(), +// )) +// } + +// pub fn get(cache: &Cache, key: &K) -> Option +// where +// K: std::hash::Hash + Eq + 'static, +// V: Clone + 'static, +// { +// cache.lock().unwrap().get(key).cloned() +// } + +// pub fn insert(cache: &Cache, key: K, value: V) +// where +// K: std::hash::Hash + Eq + 'static, +// V: Clone + 'static, +// { +// cache.lock().unwrap().insert(key, value); +// } + +// pub fn invalidate(cache: &Cache, key: &K) +// where +// K: std::hash::Hash + Eq + 'static, +// V: Clone + 'static, +// { +// cache.lock().unwrap().invalidate(key); +// } +// } /// Configuration for resolver caching #[cfg(feature = "cache")] diff --git a/crates/jacquard-oauth/src/resolver.rs b/crates/jacquard-oauth/src/resolver.rs index ced72ab2..d10b4850 100644 --- a/crates/jacquard-oauth/src/resolver.rs +++ b/crates/jacquard-oauth/src/resolver.rs @@ -5,6 +5,7 @@ use crate::types::{OAuthAuthorizationServerMetadata, OAuthProtectedResourceMetad use http::{Request, StatusCode}; use jacquard_common::CowStr; use jacquard_common::IntoStatic; +use jacquard_common::cowstr::ToCowStr; use jacquard_common::types::did_doc::DidDocument; use jacquard_common::types::ident::AtIdentifier; use jacquard_common::{http_client::HttpClient, types::did::Did}; diff --git a/crates/mini-moka-vendored/src/common.rs b/crates/mini-moka-vendored/src/common.rs index 81355179..1d497db3 100644 --- a/crates/mini-moka-vendored/src/common.rs +++ b/crates/mini-moka-vendored/src/common.rs @@ -6,7 +6,7 @@ pub(crate) mod concurrent; pub(crate) mod builder_utils; pub(crate) mod deque; pub(crate) mod frequency_sketch; -pub(crate) mod time; +pub mod time; // Note: `CacheRegion` cannot have more than four enum variants. This is because // `crate::{sync,unsync}::DeqNodes` uses a `tagptr::TagNonNull, 2>` diff --git a/crates/mini-moka-vendored/src/common/concurrent/housekeeper.rs b/crates/mini-moka-vendored/src/common/concurrent/housekeeper.rs index 8fed25d3..a78b2e28 100644 --- a/crates/mini-moka-vendored/src/common/concurrent/housekeeper.rs +++ b/crates/mini-moka-vendored/src/common/concurrent/housekeeper.rs @@ -6,12 +6,9 @@ use super::{ }, }; -use crate::common::time::{CheckedTimeOps, Instant}; +use crate::common::time::{CheckedTimeOps, Duration, Instant}; -use std::{ - sync::atomic::{AtomicBool, Ordering}, - time::Duration, -}; +use std::sync::atomic::{AtomicBool, Ordering}; pub(crate) trait InnerSync { fn sync(&self, max_sync_repeats: usize); diff --git a/crates/mini-moka-vendored/src/common/time.rs b/crates/mini-moka-vendored/src/common/time.rs index 7a2fac64..ff3d2716 100644 --- a/crates/mini-moka-vendored/src/common/time.rs +++ b/crates/mini-moka-vendored/src/common/time.rs @@ -1,4 +1,8 @@ -use std::time::Duration; +#[cfg(not(feature = "js"))] +pub type Duration = std::time::Duration; + +#[cfg(feature = "js")] +pub type Duration = web_time::Duration; pub(crate) mod clock; diff --git a/crates/mini-moka-vendored/src/lib.rs b/crates/mini-moka-vendored/src/lib.rs index e7143b27..caf9417f 100644 --- a/crates/mini-moka-vendored/src/lib.rs +++ b/crates/mini-moka-vendored/src/lib.rs @@ -66,6 +66,8 @@ pub mod unsync; #[cfg_attr(docsrs, doc(cfg(feature = "sync")))] pub mod sync; +pub use common::time; + pub use policy::Policy; #[cfg(test)] diff --git a/crates/mini-moka-vendored/src/sync/base_cache.rs b/crates/mini-moka-vendored/src/sync/base_cache.rs index 84e8bf49..6dd7bd8b 100644 --- a/crates/mini-moka-vendored/src/sync/base_cache.rs +++ b/crates/mini-moka-vendored/src/sync/base_cache.rs @@ -15,7 +15,7 @@ use crate::{ }, deque::{DeqNode, Deque}, frequency_sketch::FrequencySketch, - time::{CheckedTimeOps, Clock, Instant}, + time::{CheckedTimeOps, Clock, Duration, Instant}, CacheRegion, }, Policy, @@ -34,7 +34,6 @@ use std::{ atomic::{AtomicBool, Ordering}, Arc, Mutex, RwLock, }, - time::Duration, }; use triomphe::Arc as TrioArc; diff --git a/crates/mini-moka-vendored/src/sync/builder.rs b/crates/mini-moka-vendored/src/sync/builder.rs index 77b34b4c..0d70ed4b 100644 --- a/crates/mini-moka-vendored/src/sync/builder.rs +++ b/crates/mini-moka-vendored/src/sync/builder.rs @@ -1,12 +1,11 @@ use super::Cache; -use crate::{common::builder_utils, common::concurrent::Weigher}; +use crate::{common::builder_utils, common::concurrent::Weigher, common::time::Duration}; use std::{ collections::hash_map::RandomState, hash::{BuildHasher, Hash}, marker::PhantomData, sync::Arc, - time::Duration, }; /// Builds a [`Cache`][cache-struct] or with various configuration knobs. diff --git a/crates/mini-moka-vendored/src/sync/cache.rs b/crates/mini-moka-vendored/src/sync/cache.rs index a5fd4663..27107664 100644 --- a/crates/mini-moka-vendored/src/sync/cache.rs +++ b/crates/mini-moka-vendored/src/sync/cache.rs @@ -6,6 +6,7 @@ use crate::{ housekeeper::{Housekeeper, InnerSync}, Weigher, WriteOp, }, + time::Duration, time::Instant, }, Policy, @@ -18,7 +19,6 @@ use std::{ fmt, hash::{BuildHasher, Hash}, sync::Arc, - time::Duration, }; /// A thread-safe concurrent in-memory cache built upon [`dashmap::DashMap`][dashmap]. diff --git a/examples/app_password_create_post.rs b/examples/app_password_create_post.rs index 950d04e0..86fe7a2e 100644 --- a/examples/app_password_create_post.rs +++ b/examples/app_password_create_post.rs @@ -23,7 +23,7 @@ async fn main() -> miette::Result<()> { let args = Args::parse(); let (session, auth) = - MemoryCredentialSession::authenticated(args.input, args.password, None).await?; + MemoryCredentialSession::authenticated(args.input, args.password, None, None).await?; println!("Signed in as {}", auth.handle); let agent: Agent<_> = Agent::from(session); -- 2.51.2