예제 #1
0
        private static async Task OnCompletedRequestAsync(object sender, ClientRequestEventArgs clientRequest)
        {
            var content = StringCompressor.CompressString(clientRequest.ResponseContent);

            var cacheItem = new CacheItem()
            {
                Url     = clientRequest.Url,
                Content = content
            };

            using var cacheContext = new CacheContext();
            await cacheContext.CacheItems.AddAsync(cacheItem);

            await cacheContext.SaveChangesAsync();
        }
예제 #2
0
        private static async Task OnBeforeRequestAsync(object sender, ClientRequestEventArgs e)
        {
            var client        = sender as Client;
            var clientRequest = e as ClientRequestEventArgs;

            using var cacheContext = new CacheContext();
            var item = cacheContext
                       .CacheItems
                       .Where(i => i.Url.ToLower() == clientRequest.Url.ToLower())
                       .Select(i => i.Content);

            var content = item.FirstOrDefault();

            if (content == null)
            {
                return;
            }

            var contentText = StringCompressor.DecompressString(content);

            clientRequest.ResponseContent = contentText;
        }