Skip to content

Commit

Permalink
avoid throwing err
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed May 23, 2024
1 parent e6e07ed commit a5ecc2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
27 changes: 14 additions & 13 deletions src/core/lambda/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ impl Eval for Cache {
) -> Pin<Box<dyn Future<Output = Result<ConstValue, EvaluationError>> + 'a + Send>> {
Box::pin(async move {
if let Expression::IO(io) = self.expr.deref() {
let key = io
.cache_key(&ctx)
.ok_or(anyhow::anyhow!("Unable to generate Cache Key"))?;

if let Some(val) = ctx.request_ctx.runtime.cache.get(&key).await? {
Ok(val)
let key = io.cache_key(&ctx);
if let Some(key) = key {
if let Some(val) = ctx.request_ctx.runtime.cache.get(&key).await? {
Ok(val)
} else {
let val = self.expr.eval(ctx.clone()).await?;
ctx.request_ctx
.runtime
.cache
.set(key, val.clone(), self.max_age)
.await?;

Check warning on line 53 in src/core/lambda/cache.rs

View check run for this annotation

Codecov / codecov/patch

src/core/lambda/cache.rs#L53

Added line #L53 was not covered by tests
Ok(val)
}
} else {
let val = self.expr.eval(ctx.clone()).await?;
ctx.request_ctx
.runtime
.cache
.set(key, val.clone(), self.max_age)
.await?;
Ok(val)
self.expr.eval(ctx).await

Check warning on line 57 in src/core/lambda/cache.rs

View check run for this annotation

Codecov / codecov/patch

src/core/lambda/cache.rs#L57

Added line #L57 was not covered by tests
}
} else {
Ok(self.expr.eval(ctx).await?)
Expand Down
20 changes: 11 additions & 9 deletions src/core/lambda/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ impl Eval for IO {
) -> Pin<Box<dyn Future<Output = Result<ConstValue, EvaluationError>> + 'a + Send>> {
if ctx.request_ctx.upstream.dedupe {
Box::pin(async move {
let key = self
.cache_key(&ctx)
.ok_or(anyhow::anyhow!("Unable to generate Cache Key"))?;
ctx.request_ctx
.cache
.get_or_eval(key, move || Box::pin(self.eval_inner(ctx)))
.await
.as_ref()
.clone()
let key = self.cache_key(&ctx);
if let Some(key) = key {
ctx.request_ctx
.cache
.get_or_eval(key, move || Box::pin(self.eval_inner(ctx)))
.await

Check warning on line 59 in src/core/lambda/io.rs

View check run for this annotation

Codecov / codecov/patch

src/core/lambda/io.rs#L59

Added line #L59 was not covered by tests
.as_ref()
.clone()
} else {
self.eval_inner(ctx).await

Check warning on line 63 in src/core/lambda/io.rs

View check run for this annotation

Codecov / codecov/patch

src/core/lambda/io.rs#L63

Added line #L63 was not covered by tests
}
})
} else {
Box::pin(self.eval_inner(ctx))
Expand Down

0 comments on commit a5ecc2c

Please sign in to comment.