Last active
April 16, 2022 14:56
-
-
Save nishanc/a48d610b429667411a1d3d51d00979de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> Index() | |
{ | |
List<User>? users; | |
string recordKey = $"Users_{DateTime.Now:yyyyMMdd_hhmm}"; | |
users = await _cache.GetRecordAsync<List<User>>(recordKey); // Get data from cache | |
if (users is null) // Data not available in the Cache | |
{ | |
users = await _userRepository.GetUsersAsync(); // Read data from database | |
await _cache.SetRecordAsync(recordKey, users); // Set cache | |
} | |
return View(users); // Return data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment