private static async Task <T> GetAsync <T>(this ObjectCache cache, string key, Func <Task <T> > acquireAsync, Action <string, object> set) { string cacheKey = CacheKeyGenerator.GenerateCacheKey <T>(key); if (cache.IsSet(cacheKey)) { var acquiredValue = cache.Get(cacheKey); if (acquiredValue is NullObject) { return(default(T)); } return((T)acquiredValue); } using (await CacheLock.LockAsync(cacheKey)) { if (cache.IsSet(cacheKey)) { return((T)cache.Get(cacheKey)); } var acquiredValue = await acquireAsync(); if (acquiredValue != null) { set(cacheKey, acquiredValue); } else { set(cacheKey, NullObject.Instance); } return(acquiredValue); } }