ASP.NET Core MVC Interview Question #190
How would you design caching for an MVC product catalog?
Senior Practical MVC Scenarios & Production Architecture Senior Advanced
Quick Interview Answer
Identify data that is expensive to produce, frequently requested, and safe to reuse. Public catalog pages may use output caching, while reusable lookup data can use memory or distributed caching.
Detailed Explanation
Identify data that is expensive to produce, frequently requested, and safe to reuse. Public catalog pages may use output caching, while reusable lookup data can use memory or distributed caching.
Define expiration and invalidation behavior before adding the cache. Include every value that changes the response in the cache policy, and never allow personalized or permission-sensitive output to be shared across users accidentally.
Code Example
[OutputCache(PolicyName = "PublicCatalog")]
public async Task<IActionResult> Index(
int page = 1,
CancellationToken token = default)
{
var model = await _catalog.GetPageAsync(page, token);
return View(model);
}