ASP.NET Core Interview Question #180
What is IDistributedCache?
Performance, Caching & HTTP Senior Advanced
Quick Interview Answer
IDistributedCache is an abstraction for a cache that can be shared by multiple application instances. Implementations can use external distributed storage rather than the memory of one web process.
Detailed Explanation
IDistributedCache is an abstraction for a cache that can be shared by multiple application instances. Implementations can use external distributed storage rather than the memory of one web process.
It exposes byte-array and string-oriented operations, so complex objects normally require serialization. Distributed caching adds network and serialization overhead but provides shared cache state across instances.
Applications should still design expiration and invalidation carefully.
Code Example
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration =
builder.Configuration.GetConnectionString("Redis");
options.InstanceName = "MyApp:";
});