private async Task <CacheResponse <IEsiFragment> > RequestAndParse(
            Uri uri, EsiExecutionContext executionContext)
        {
            var response = await _httpLoader.Get(uri, executionContext);

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var fragment = _esiBodyParser.Parse(content);

            return(CacheResponse.Create(fragment, response.Headers.CacheControl, response.Headers.Vary.ToList()));
        }
Esempio n. 2
0
        private async Task StoreFragmentInCache(
            HttpContext context, Uri pageUri, EsiExecutionContext executionContext, IEsiFragment fragment)
        {
            CacheControlHeaderValue.TryParse(
                context.Response.Headers[HeaderNames.CacheControl], out var cacheControl);

            if (ShouldSetCache(context))
            {
                var headers      = context.Response.Headers.ToDictionary();
                var pageResponse = new FragmentPageResponse(fragment, headers);

                var vary          = context.Response.Headers[HeaderNames.Vary];
                var cacheResponse = CacheResponse.Create(pageResponse, cacheControl, vary);

                await _cache.Set(pageUri, executionContext, cacheResponse);
            }
        }