Skip to content

Commit d2921d9

Browse files
committed
add dashmap
1 parent a7e4403 commit d2921d9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

projects/ssddOnTop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ http = "1.1.0"
4949
url = "2.5.2"
5050
schemars = {version = "0.8.17", features = ["derive"]}
5151
async-recursion = "1.1.1"
52+
dashmap = "6.1.0"
5253

5354
[dev-dependencies]
5455
http-cache = "0.18.0"

projects/ssddOnTop/src/ir/eval_io.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use std::num::NonZeroU64;
88
pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result<Value> {
99
let key = io.cache_key(ctx);
1010

11-
if let Some(val) = ctx.request_ctx.cache.get(&key).await? {
11+
if let Some(val) = ctx.request_ctx.cache.get(&key) {
1212
Ok(val.clone())
1313
} else {
1414
let val = eval_io_inner(io, ctx).await?;
1515
ctx.request_ctx
1616
.cache
17-
.set(key, val.clone(), NonZeroU64::MAX)
18-
.await?;
17+
.insert(key, val.clone());
1918
Ok(val)
2019
}
2120
}

projects/ssddOnTop/src/request_context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use anyhow::Error;
88
use derive_setters::Setters;
99
use std::num::NonZeroU64;
1010
use std::sync::{Arc, Mutex};
11+
use dashmap::DashMap;
1112

1213
#[derive(Clone)]
1314
pub struct CacheErr(String);
@@ -31,7 +32,8 @@ pub struct RequestContext {
3132
pub min_max_age: Arc<Mutex<Option<i32>>>,
3233
pub cache_public: Arc<Mutex<Option<bool>>>,
3334
pub runtime: TargetRuntime,
34-
pub cache: InMemoryCache<IoId, Value>,
35+
pub cache: DashMap<IoId, Value>,
36+
// pub cache: InMemoryCache<IoId, Value>,
3537
// pub cache: Dedupe<IoId, Result<Value, CacheErr>>,
3638
}
3739

@@ -44,7 +46,8 @@ impl RequestContext {
4446
cache_public: Arc::new(Mutex::new(None)),
4547
runtime: target_runtime,
4648
// cache: Dedupe::new(1, true),
47-
cache: InMemoryCache::new(),
49+
// cache: InMemoryCache::new(),
50+
cache: Default::default(),
4851
}
4952
}
5053
fn set_min_max_age_conc(&self, min_max_age: i32) {
@@ -99,7 +102,8 @@ impl From<&AppCtx> for RequestContext {
99102
cache_public: Arc::new(Mutex::new(None)),
100103
runtime: app_ctx.runtime.clone(),
101104
// cache: Dedupe::new(1, true),
102-
cache: InMemoryCache::new(),
105+
// cache: InMemoryCache::new(),
106+
cache: Default::default(),
103107
}
104108
}
105109
}

0 commit comments

Comments
 (0)