public IActionResult GetPatients() { Log.Information("Getting information about patients"); var cacheKey = "Patients"; var patientsData = _distributedCache.GetString(cacheKey); if (!string.IsNullOrEmpty(patientsData)) { Log.Information("Using cached data"); return(Ok(JsonConvert.DeserializeObject <List <Patient> >(patientsData))); } var patients = _patientBusiness.GetPatients(); DistributedCacheEntryOptions patientsExpiration = new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.UtcNow.AddSeconds(30) }; _distributedCache.SetString(cacheKey, JsonConvert.SerializeObject(patients), patientsExpiration); Log.Information("Added new data to cache"); return(Ok(patients)); }