public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state) { string cacheKey = this.CreateCacheKey(inputs); CachedOperationResult cachedItem = CacheServiceHelper.Current.Get <CachedOperationResult>(cacheKey); CachingUserState cachingUserState = new CachingUserState { CacheItem = cachedItem, CacheKey = cacheKey, Callback = callback, State = state }; IAsyncResult originalAsyncResult; if (cachedItem != null) { InvokerDelegate invoker = cachedItem.GetValue; object[] notUsed; originalAsyncResult = invoker.BeginInvoke(inputs, out notUsed, this.InvokerCallback, cachingUserState); } else { originalAsyncResult = _invoker.InvokeBegin(instance, inputs, this.InvokerCallback, cachingUserState); } return(new CachingAsyncResult(originalAsyncResult, cachingUserState)); }
public object Invoke(object instance, object[] inputs, out object[] outputs) { string cacheKey = this.CreateCacheKey(inputs); CachedOperationResult cachedItem = CacheServiceHelper.Current.Get <CachedOperationResult>(cacheKey); if (cachedItem != null) { LoggerServiceHelper.Current.WriteLine(this, LogStatusEnum.Debug, "{0}.{1} -> Gets method result from cache", _operation.DeclaringContract.ContractType, _operation.Name); outputs = cachedItem.Outputs; return(cachedItem.Data); } object data = _invoker.Invoke(instance, inputs, out outputs); if (_cacheDuration > 0) { cachedItem = new CachedOperationResult { Data = data, Outputs = outputs }; CacheServiceHelper.Current.Add(cacheKey, cachedItem, TimeSpan.FromSeconds(_cacheDuration)); } return(data); }