コード例 #1
0
        public void Process(System.Web.HttpContext current, IResponseArgs e)
        {
            var modDate = e.HasModifiedDate ? e.GetModifiedDateUTC() : DateTime.MinValue;
            var key     = e.RequestKey + "|" + modDate.Ticks.ToString(NumberFormatInfo.InvariantInfo);

            CacheEntry entry;

            byte[] data;

            //Ensure cache is loaded
            if (!loaded)
            {
                Load();
            }

            if (!TryGetData(key, out data, out entry))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                //Cache miss - process request, outside of lock
                MemoryStream ms = new MemoryStream(4096);
                e.ResizeImageToStream(ms);
                data = StreamExtensions.CopyToBytes(ms, true);
                sw.Stop();
                //Save to cache
                entry = PutData(key, data, sw.ElapsedMilliseconds);
            }

            ((ResponseArgs)e).ResizeImageToStream = delegate(Stream s) {
                s.Write(data, 0, data.Length);
            };

            current.RemapHandler(new NoCacheHandler(e));

            if (cache.changes_since_cleanse > ChangeThreshold)
            {
                CleanseAndFlush();
            }
            else if (cache.changes_since_cleanse > 0 && DateTime.UtcNow.Subtract(lastFlush) > new TimeSpan(0, 0, 30))
            {
                Flush();
            }
        }
コード例 #2
0
ファイル: NoCache.cs プロジェクト: hwebz/NTCWeb
 /// <summary>
 /// Sends the response directly to the client with no caching logic.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="e"></param>
 public void Process(System.Web.HttpContext context, IResponseArgs e)
 {
     context.RemapHandler(new NoCacheHandler(e));
     // The following line of code does nothing. I don't think there is any way to make this work before .NET 2.0 SP2
     //context.Handler = new NoCacheHandler(e);
 }
コード例 #3
0
ファイル: NoCache.cs プロジェクト: timgaunt/resizer
 public System.Threading.Tasks.Task ProcessAsync(System.Web.HttpContext context, IAsyncResponsePlan e)
 {
     context.RemapHandler(new NoCacheAsyncHandler(e));
     return(Task.FromResult(true));
 }