Ejemplo n.º 1
0
        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 IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
#if Webhosted
            Cache cache = GetCache();
#else
            ObjectCache cache = this.GetCache();
#endif
            string           cacheKey         = this.CreateCacheKey(inputs);
            CachedResult     cacheItem        = cache[cacheKey] as CachedResult;
            CachingUserState cachingUserState = new CachingUserState
            {
                CacheItem            = cacheItem,
                CacheKey             = cacheKey,
                OriginalUserCallback = callback,
                OriginalUserState    = state
            };

            IAsyncResult originalAsyncResult;
            if (cacheItem != null)
            {
                InvokerDelegate invoker = cacheItem.GetValue;
                object[]        dummy;
                originalAsyncResult = invoker.BeginInvoke(inputs, out dummy, this.InvokerCallback, cachingUserState);
            }
            else
            {
                originalAsyncResult = this.originalInvoker.InvokeBegin(instance, inputs, this.InvokerCallback, cachingUserState);
            }

            return(new CachingAsyncResult(originalAsyncResult, cachingUserState));
        }