public static async Task <T> GetOrAdd <T>(this ICacheItem <T> self, ICacheItemLock lockObj, Func <Task <T> > getProc, bool continueOnCapturedContext = false) { var cacheValue = await self.Get().ConfigureAwait(continueOnCapturedContext); if (cacheValue.HasValue) { return(cacheValue.Value); } await lockObj.Acquire().ConfigureAwait(continueOnCapturedContext);; try { cacheValue = await self.Get().ConfigureAwait(continueOnCapturedContext); if (cacheValue.HasValue) { return(cacheValue.Value); } var value = await getProc().ConfigureAwait(continueOnCapturedContext); await self.Set(value).ConfigureAwait(continueOnCapturedContext); return(value); } finally { await lockObj.Release().ConfigureAwait(continueOnCapturedContext); } }
public static object ShowPropertyData( [ExcelArgument(Name = "ObjectHandle", Description = "Handle to an object.")] string h, [ExcelArgument(Name = "[Property]", Description = "Name of the property being retrieved.")] object p) { object res = ExcelError.ExcelErrorNA; if (_cache.ContainsKey(h)) { ICacheItem handle = _cache.Lookup(h) as CacheItem; if (!(p is ExcelMissing)) { res = handle.Get(p.ToString()); } else { res = handle.Get(); } if (handle.Exception != null) { res = handle.Exception.Message; } } return(res); }