public bool SaveToCache()
            {
                if (_responseCapture != null)
                {
                    _rule = _rule ?? GetMatchingRule();
                    if (_rule != null && _rule.ServerCacheTime.HasValue && _rule.ServerCacheTime.Value > TimeSpan.Zero)
                    {
                        if (_cachedResponse == null)
                        {
                            _cachedResponse = new CachedResponse();
                        }

                        var buffer = _responseCapture.OutputBuffer;
                        if (buffer != null)
                        {
                            _cachedResponse.CachedContent = new byte[buffer.Length];
                            buffer.CopyTo(_cachedResponse.CachedContent, 0);

                            _cachedResponse.Headers = _context.Response.Headers.Keys
                                                      .Where(n => !_noCacheHeaders.Contains(n.ToLower()))
                                                      .Select(n => new CachedHeader {
                                HeaderName = n, HeaderValue = _context.Response.Headers[n]
                            })
                                                      .ToArray();

                            _cachedResponse.WhenCached = DateTime.UtcNow;

                            _cache.Put(_cacheKey, _cachedResponse, _rule.ServerCacheTime.Value, _rule.CacheCategory);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            public void CaptureResponse()
            {
                _responseCapture = new ResponseCapture(_context);

                _context.Response.OnSendingHeaders(c =>
                {
                    _rule = _rule ?? GetMatchingRule();
                    if (_rule.BrowserCacheTime.HasValue)
                    {
                        _context.Response.Expires = DateTime.UtcNow + _rule.BrowserCacheTime;
                        _context.Response.Headers.Set(
                            "Cache-Control",
                            "public, max-age=" + (int)_rule.BrowserCacheTime.Value.TotalSeconds);
                    }
                    else
                    {
                        _context.Response.Headers.Set("Cache-Control", "no-cache");
                    }
                }, _context);
            }