public void AddData(CacheEntry entry)
        {
            var key = entry.Key.ToString();
            var cacheItemPolicy = new CacheItemPolicy();
            if (entry.Expires.HasValue)
            {
                cacheItemPolicy.AbsoluteExpiration = entry.Expires.Value;
            }

            _cache.AddOrGetExisting(key, entry, cacheItemPolicy, _regionName);
        }
 public CacheEntry MakeEntry(HttpWebRequest request, string profile, HttpWebResponse response, List<Tuple<string, string>> headers, DateTime? expires)
 {
     var newEntry = new CacheEntry
     {
         Expires = expires,
         DateStored = DateTime.Now,
         Headers = headers,
         Key = new CacheKey(request.RequestUri.AbsoluteUri, request.UserAgent, profile),
         StatusCode = response.StatusCode,
         StatusDescription = response.StatusDescription
     };
     if (response.ContentLength > 0)
     {
         newEntry.ResponseBytes = new byte[response.ContentLength];
     }
     return newEntry;
 }
 private void ResponseFromCache(Stream outStream, CacheEntry cacheEntry)
 {
     //serve from cache
     var responseWriter = new StreamWriter(outStream);
     try
     {
         WriteResponseStatus(cacheEntry.StatusCode, cacheEntry.StatusDescription, responseWriter);
         WriteResponseHeaders(responseWriter, cacheEntry.Headers);
         if (cacheEntry.ResponseBytes != null)
         {
             var loggerOutput = new StringBuilder();
             outStream.Write(cacheEntry.ResponseBytes, 0, cacheEntry.ResponseBytes.Length);
             if (_proxyServerConfiguration.DumpResponseData)
             {
                 loggerOutput.Append(UTF8Encoding.UTF8.GetString(cacheEntry.ResponseBytes));
             }
         }
         responseWriter.Close();
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
     finally
     {
         responseWriter.Close();
     }
 }