ASP.NET Core MVC Interview Question #144
What is distributed caching and when is it preferable?
Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced
Quick Interview Answer
A distributed cache stores cached data in an external system shared by multiple application instances. It is useful in load-balanced deployments when instances need access to common cached values or distributed session data.
Detailed Explanation
A distributed cache stores cached data in an external system shared by multiple application instances. It is useful in load-balanced deployments when instances need access to common cached values or distributed session data.
Distributed caching introduces serialization, network, expiration, and failure considerations. Cache data should be treated as disposable acceleration data rather than the sole authoritative copy of critical business information.
Code Example
public async Task<string?> GetValueAsync(
string key,
CancellationToken token)
{
return await _cache.GetStringAsync(key, token);
}