alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.71k stars 159 forks source link

TryGetValue() fails (wrong value type) if the value was added Async. #194

Open DavidThielen opened 5 months ago

DavidThielen commented 5 months ago

I suggest the following code instead:

       public static bool ExTryGetValue<T>(this IAppCache service, string key, out T? value) where T : class
       {
           var item = service.Get<T>(key);
           if (item is null)
           {
               value = null;
               return false;
           }
           value = item;
           return true;
       }