⚡ Built-in Cache
Redis overkill for small apps. IMemoryCache built into .NET. Zero config.
// Startup
services.AddMemoryCache();
// Usage
public class UserService
{
private readonly IMemoryCache _cache;
public async Task GetUserAsync(int id)
{
return await _cache.GetOrCreateAsync(
$"user-{id}",
async entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
return await _db.Users.FindAsync(id);
}
);
}
}
When It’s Enough: Single server, moderate traffic, <10GB cache needs.
Upgrade Path: Later swap to Redis. Same IDistributedCache interface.
