Created
May 21, 2023 11:58
-
-
Save AndyButland/c4381e84c047091fef2ac56581334ff6 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
var cacheKey = string.Format(ApplicationServices.Constants.DistributedCache.CacheKeyFormats.CategoryById, id); | |
CategoryDto? categoryDto = await _distributedCache.GetAsync<CategoryDto>(cacheKey); | |
if (categoryDto is not null) | |
{ | |
return categoryDto; | |
} | |
categoryDto = await _categoryService.GetCategoryById(id); | |
if (categoryDto is null) | |
{ | |
return NotFound(); | |
} | |
await _distributedCache.SetAsync(cacheKey, categoryDto); | |
return Ok(categoryDto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment