Esempio n. 1
0
        public Task ProcessAsync(HttpContext current, IAsyncResponsePlan e)
        {
            //Use alternate cache key if provided
            string key = e.RequestCachingKey;

            //If cached, serve it.
            var c = cache.Get(key);

            if (c != null)
            {
                Serve(current, e, c);
                return(Task.FromResult(0));
            }
            //If not, let's cache it.
            return(asyncLocks.TryExecuteAsync(key, 3000, async delegate()
            {
                c = cache.Get(key);
                if (c == null)
                {
                    using (var data = new MemoryStream(4096))
                    {
                        await e.CreateAndWriteResultAsync(data, e);//Very long-running call
                        c = new MemCacheResult(data.CopyToBytes(true));
                    }
                    cache.Set(key, c);//Save to cache (may trigger cleanup)
                }
                Serve(current, e, c);
                return;
            }));
        }
Esempio n. 2
0
        public void Process(System.Web.HttpContext current, IResponseArgs e)
        {
            //Use alternate cache key if provided
            string key = e.RequestKey;

            //If cached, serve it.
            var c = cache.Get(key);

            if (c != null)
            {
                Serve(current, e, c);
                return;
            }
            //If not, let's cache it.
            locks.TryExecute(key, 3000, delegate() {
                c = cache.Get(key);
                if (c == null)
                {
                    using (var data = new MemoryStream()){
                        e.ResizeImageToStream(data);//Very long-running call
                        c = new MemCacheResult(data.CopyToBytes(true));
                    }
                    cache.Set(key, c);//Save to cache (may trigger cleanup)
                }
                Serve(current, e, c);
                return;
            });
        }
Esempio n. 3
0
        public void Process(System.Web.HttpContext current, IResponseArgs e)
        {
            //Use alternate cache key if provided
            string key = e.RequestKey + (e.HasModifiedDate ? e.GetModifiedDateUTC().Ticks.ToString() : "");

            //If cached, serve it.
            var c = cache.Get(key);
            if (c != null) {
                Serve(current, e, c);
                return;
            }
            //If not, let's cache it.
            locks.TryExecute(key, 3000, delegate() {
                c = cache.Get(key);
                if (c == null) {
                    using (var data = new MemoryStream()){
                        e.ResizeImageToStream(data);//Very long-running call
                        c = new MemCacheResult(StreamExtensions.CopyToBytes(data, true));
                    }
                    cache.Set(key, c);//Save to cache (may trigger cleanup)
                }
                Serve(current, e, c);
                return;
            });
        }
Esempio n. 4
0
 private void Serve(HttpContext context, IAsyncResponsePlan e, MemCacheResult result)
 {
     context.RemapHandler(new MemCacheHandler(e, result.Data));
 }
Esempio n. 5
0
 private void Serve(HttpContext context, IResponseArgs e, MemCacheResult result)
 {
     context.RemapHandler(new MemCacheHandler(e,result.Data));
 }