Exemple #1
0
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            if (OperationCache == null)
            {
                return(InnerOperationInvoker.InvokeEnd(instance, out outputs, result));
            }

            OperationCachingInvokerAsyncResult asyncResult = result as OperationCachingInvokerAsyncResult;

            if (asyncResult == null)
            {
                throw new ArgumentException("Invalid AsyncResult", "result");
            }
            OperationCachingInvokerAsyncResult.End(asyncResult);

            if (asyncResult.IsNewResult)
            {
                OperationCacheKey   key   = new OperationCacheKey(asyncResult.Action, asyncResult.Inputs);
                OperationCacheValue value = new OperationCacheValue(asyncResult.Outputs, asyncResult.ReturnValue);
                OperationCache.Insert(key, value);
            }

            outputs = asyncResult.Outputs;
            return(asyncResult.ReturnValue);
        }
Exemple #2
0
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            if (OperationCache == null)
            {
                return(InnerOperationInvoker.InvokeBegin(instance, inputs, callback, state));
            }

            OperationCacheKey   key   = new OperationCacheKey(action, inputs);
            OperationCacheValue value = OperationCache.Lookup(key);

            // if it's not in the cache, let the async invoke and let the end handle caching
            if (value == null)
            {
                return(new OperationCachingInvokerAsyncResult(instance, action, inputs, innerOperationInvoker, callback, state));
            }

            // otherwise, just pass all the data to the async result and let it complete synchronously
            return(new OperationCachingInvokerAsyncResult(instance, action, inputs, value.ReturnValue, value.Outputs, callback, state));
        }