public void Set(string key, IResponseCacheEntry entry, TimeSpan validFor) { if (entry is CachedResponse cachedResponse) { var segmentStream = new SegmentWriteStream(StreamUtilities.BodySegmentSize); cachedResponse.Body.CopyTo(segmentStream); _cache.Set( key, new MemoryCachedResponse { Created = cachedResponse.Created, StatusCode = cachedResponse.StatusCode, Headers = cachedResponse.Headers, BodySegments = segmentStream.GetSegments(), BodyLength = segmentStream.Length }, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = validFor, Size = CacheEntryHelpers.EstimateCachedResponseSize(cachedResponse) }); } else { _cache.Set( key, entry, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = validFor, Size = CacheEntryHelpers.EstimateCachedVaryByRulesySize(entry as CachedVaryByRules) }); } }
internal CachedResponseBody GetCachedResponseBody() { if (!BufferingEnabled) { throw new InvalidOperationException("Buffer stream cannot be retrieved since buffering is disabled."); } return(new CachedResponseBody(_segmentWriteStream.GetSegments(), _segmentWriteStream.Length)); }
internal Stream GetBufferStream() { if (!BufferingEnabled) { throw new InvalidOperationException("Buffer stream cannot be retrieved since buffering is disabled."); } return(new SegmentReadStream(_segmentWriteStream.GetSegments(), _segmentWriteStream.Length)); }