Skip to content

Instantly share code, notes, and snippets.

@nishanc
Last active April 16, 2022 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/a48d610b429667411a1d3d51d00979de to your computer and use it in GitHub Desktop.
Save nishanc/a48d610b429667411a1d3d51d00979de to your computer and use it in GitHub Desktop.
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