-
Hey everyone, I'm using HybridCache and ran into a small dilemma. My delegate returns a Here's what I have: public delegate Task<TResponse> RequestHandlerDelegate<TResponse>(); And HybridCache wants: Func<CancellationToken, ValueTask<T>> factory So I've got two ways to do this: Option 1: return await _cache.GetOrCreateAsync(
request.Id.ToString(),
_ => new ValueTask<TResponse>(next()),
_cacheOptions); Option 2: return await _cache.GetOrCreateAsync(
request.Id.ToString(),
async _ => await next(),
_cacheOptions); I'm leaning towards option 1 because it seems like option 2 is just adding an extra async/await for no reason? But maybe I'm missing something. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Option 1. It's as you said that the async-machinery can be avoided, as it doesn't add any benefit here (only more code and overhead here). |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks for a quick answer. Any specific reason why HybridCache doesn't accept factory which returns
|
Beta Was this translation helpful? Give feedback.
Option 1.
It's as you said that the async-machinery can be avoided, as it doesn't add any benefit here (only more code and overhead here).