Skip to content

Instantly share code, notes, and snippets.

@AndyButland
Created May 21, 2023 11:58
Show Gist options
  • Save AndyButland/c4381e84c047091fef2ac56581334ff6 to your computer and use it in GitHub Desktop.
Save AndyButland/c4381e84c047091fef2ac56581334ff6 to your computer and use it in GitHub Desktop.
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