Skip to content

Commit

Permalink
add dashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Sep 13, 2024
1 parent a7e4403 commit d2921d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/ssddOnTop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ http = "1.1.0"
url = "2.5.2"
schemars = {version = "0.8.17", features = ["derive"]}
async-recursion = "1.1.1"
dashmap = "6.1.0"

[dev-dependencies]
http-cache = "0.18.0"
Expand Down
5 changes: 2 additions & 3 deletions projects/ssddOnTop/src/ir/eval_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use std::num::NonZeroU64;
pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result<Value> {
let key = io.cache_key(ctx);

if let Some(val) = ctx.request_ctx.cache.get(&key).await? {
if let Some(val) = ctx.request_ctx.cache.get(&key) {
Ok(val.clone())
} else {
let val = eval_io_inner(io, ctx).await?;
ctx.request_ctx
.cache
.set(key, val.clone(), NonZeroU64::MAX)
.await?;
.insert(key, val.clone());
Ok(val)
}
}
Expand Down
10 changes: 7 additions & 3 deletions projects/ssddOnTop/src/request_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::Error;
use derive_setters::Setters;
use std::num::NonZeroU64;
use std::sync::{Arc, Mutex};
use dashmap::DashMap;

#[derive(Clone)]
pub struct CacheErr(String);
Expand All @@ -31,7 +32,8 @@ pub struct RequestContext {
pub min_max_age: Arc<Mutex<Option<i32>>>,
pub cache_public: Arc<Mutex<Option<bool>>>,
pub runtime: TargetRuntime,
pub cache: InMemoryCache<IoId, Value>,
pub cache: DashMap<IoId, Value>,
// pub cache: InMemoryCache<IoId, Value>,
// pub cache: Dedupe<IoId, Result<Value, CacheErr>>,
}

Expand All @@ -44,7 +46,8 @@ impl RequestContext {
cache_public: Arc::new(Mutex::new(None)),
runtime: target_runtime,
// cache: Dedupe::new(1, true),
cache: InMemoryCache::new(),
// cache: InMemoryCache::new(),
cache: Default::default(),
}
}
fn set_min_max_age_conc(&self, min_max_age: i32) {
Expand Down Expand Up @@ -99,7 +102,8 @@ impl From<&AppCtx> for RequestContext {
cache_public: Arc::new(Mutex::new(None)),
runtime: app_ctx.runtime.clone(),
// cache: Dedupe::new(1, true),
cache: InMemoryCache::new(),
// cache: InMemoryCache::new(),
cache: Default::default(),
}
}
}

0 comments on commit d2921d9

Please sign in to comment.