Skip to content

Commit

Permalink
try dashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Sep 13, 2024
1 parent 6f49528 commit 5b1946c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 5 additions & 8 deletions projects/ssddOnTop/src/ir/eval_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ use crate::value::Value;
use std::num::NonZeroU64;

pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result<Value> {
let val = eval_io_inner(io, ctx).await?;
Ok(val)
/* let key = io.cache_key(ctx);
let key = io.cache_key(ctx);

if let Some(val) = ctx.request_ctx.cache.get(&key).await? {
Ok(val.clone())
if let Some(val) = ctx.request_ctx.cache.get(&key) {
Ok(val.value().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)
}*/
}
}

async fn eval_io_inner(io: &IO, ctx: &mut EvalContext<'_>) -> Result<Value, CacheErr> {
Expand Down
11 changes: 8 additions & 3 deletions projects/ssddOnTop/src/request_context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use crate::app_ctx::AppCtx;
use crate::blueprint::{Server, Upstream};
use crate::ir::IoId;
Expand All @@ -8,6 +9,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 +33,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 +47,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 +103,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 5b1946c

Please sign in to comment.