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; })); }
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; }); }
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; }); }
private void Serve(HttpContext context, IAsyncResponsePlan e, MemCacheResult result) { context.RemapHandler(new MemCacheHandler(e, result.Data)); }
private void Serve(HttpContext context, IResponseArgs e, MemCacheResult result) { context.RemapHandler(new MemCacheHandler(e,result.Data)); }