private void OutputCache(PageCacheItem value, HttpContext context) { byte[] data = Encoding.ASCII.GetBytes("0\r\n\r\n"); context.Response.BinaryWrite(value.Data); context.Response.BinaryWrite(data); context.Response.Flush(); context.Response.End(); }
private void Cache_WithWeb(HttpContext context, HttpRequest request, string key) { PageCacheItem data = (PageCacheItem)context.Cache[key]; if (data == null) { Generator_Cache(context, request, key); } else { OutputCache(data, context); } }
public override void Execute() { lock (typeof(GetUrlItem)) { PageCacheItem page = new PageCacheItem(); mRequest = (HttpWebRequest)WebRequest.Create(URL); mResponse = (HttpWebResponse)mRequest.GetResponse(); int length = 0; foreach (string key in mResponse.Headers.Keys) { page.Headers.Add(new HeaderItem { Name = key, Value = mResponse.Headers[key] }); if (key == "Content-Length") { int.TryParse(mResponse.Headers[key], out length); } } page.Data = new Byte[length]; int offset = 0; int count; using (System.IO.Stream stream = mResponse.GetResponseStream()) { count = stream.Read(page.Data, offset, page.Data.Length - offset); offset += count; while (count > 0) { count = stream.Read(page.Data, offset, page.Data.Length - offset); offset += count; } } if (Cache != null && HttpModule.MenCacheEnabled) { Cache.Set(Key, page); } if (WebCache != null && HttpModule.WebCacheEnabled) { WebCache.Remove(Key); WebCache.Add(Key, page, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); } } }
public override void Execute() { lock (typeof(GetUrlItem)) { PageCacheItem page = new PageCacheItem(); mRequest = (HttpWebRequest)WebRequest.Create(URL); mResponse = (HttpWebResponse)mRequest.GetResponse(); int length=0; foreach(string key in mResponse.Headers.Keys) { page.Headers.Add(new HeaderItem{ Name=key, Value= mResponse.Headers[key]}); if (key == "Content-Length") { int.TryParse(mResponse.Headers[key], out length); } } page.Data = new Byte[length]; int offset=0; int count; using (System.IO.Stream stream = mResponse.GetResponseStream()) { count= stream.Read(page.Data, offset, page.Data.Length-offset); offset += count; while (count > 0) { count = stream.Read(page.Data, offset, page.Data.Length - offset); offset += count; } } if (Cache != null && HttpModule.MenCacheEnabled) Cache.Set(Key, page); if (WebCache != null && HttpModule.WebCacheEnabled) { WebCache.Remove(Key); WebCache.Add(Key, page, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); } } }