public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders,
                                   Stream requestStream, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            RemotingResult result = cache.GetPreviousResults(msg, requestHeaders, false);

            if (result == null)
            {
                _nextSink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders, out responseStream);
                object objCacheLimit = responseHeaders["X-Cache"];
                if (objCacheLimit != null && Convert.ToInt32(objCacheLimit) > 0)
                {
                    byte[] response = ExtractContents(responseStream);
                    //responseStream can only be read once - give back new stream
                    responseStream = new MemoryStream(response, 0, response.Length);
                    //save for next time
                    cache.CacheResults(msg, requestHeaders,
                                       new RemotingResult(response, responseHeaders, DateTime.UtcNow + TimeSpan.FromSeconds(Convert.ToInt32(objCacheLimit))), false);
                }
            }
            else
            {
                responseStream  = new MemoryStream(result.Response);
                responseHeaders = result.Headers;
            }
        }
 public RemotingResult GetPreviousResults(IMessage Msg, ITransportHeaders Headers, bool IsAsync)
 {
     try{
         RemotingResult res = (RemotingResult)_resultMap[new RemotingKey(Msg, Headers, IsAsync)];
         if (res != null && res.ValidTo < DateTime.UtcNow)
         {
             _resultMap[new RemotingKey(Msg, Headers, IsAsync)] = null;
             return(null);
         }
         return(res);
     }
     catch (Exception) {
         return(null);
     }
 }
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack,
                                        IMessage msg, ITransportHeaders headers, Stream stream)
        {
            RemotingResult result = cache.GetPreviousResults(msg, headers, true);

            if (result == null)
            {
                _asyncMessage = msg;
                _asyncHeaders = headers;
                sinkStack.Push(this, null);
                _nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
            }
            else
            {
                _asyncMessage = null;
                AsyncProcessResponse(sinkStack, null, result.Headers, new MemoryStream(result.Response));
            }
        }
 public void CacheResults(IMessage Msg, ITransportHeaders Headers, RemotingResult Result, bool IsAsync)
 {
     _resultMap[new RemotingKey(Msg, Headers, IsAsync)] = Result;
 }