public async Task <IActionResult> IndexAsync() { const string nowKey = "RedisCachedNowController_IndexAsync"; string serialized = await _distributedCache.GetStringAsync(nowKey); if (serialized != null) { _logger.LogInformation("From redis"); return(Ok(JsonSerializer.Deserialize <DateTimeDto>(serialized))); } _logger.LogInformation("Current date is requested"); var response = DateTimeDto.Now(); await _distributedCache.SetStringAsync( key : nowKey, value : JsonSerializer.Serialize(response), options : new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(3) }); return(Ok(response)); }