Caching is one of the most effective ways to improve the performance of ASP.NET Core applications. It reduces database load, decreases response times, and improves scalability. Traditionally, distributed caching with Redis has been the preferred choice for cloud-native applications. However, ASP.NET Core 11 introduces improvements around HybridCache, which combines the speed of in-memory caching with the reliability of distributed caching through a single API.
If you're building high-traffic APIs, understanding when to use HybridCache instead of Redis—or together with Redis—is important.
In this article, you'll learn how HybridCache works, how it compares to Redis, how to implement both approaches, and how to design your own benchmark methodology without relying on fabricated performance numbers.
Note: This article intentionally does not include benchmark results because no benchmark environment or measurements were provided in the research brief. Instead, it explains how to perform reproducible benchmarks in your own environment.
What Is HybridCache?
HybridCache is a caching abstraction introduced in ASP.NET Core that simplifies cache access while supporting multiple cache layers.
Instead of manually checking memory cache first and then Redis, HybridCache handles this workflow through a unified API.
Typical cache flow:
Application
│
▼
HybridCache
│
┌────┴────┐
▼ ▼
Memory Redis
Cache Cache
│
▼
Database
The first request loads data from the database, stores it in cache, and subsequent requests are served from cache until expiration.
How Redis Differs
Redis is a distributed cache that runs as an independent server.
Instead of storing data inside your application process, Redis stores cached values externally, allowing multiple application instances to share the same cache.
Advantages include:
Shared cache across servers
High availability
Large cache capacity
Suitable for cloud deployments
The tradeoff is network latency because every cache lookup requires communication with the Redis server.
HybridCache vs Redis
| Feature | HybridCache | Redis |
|---|---|---|
| In-memory cache | Yes | No |
| Distributed cache | Yes (when configured) | Yes |
| Single API | Yes | No |
| Network round-trip | Often avoided | Required |
| Multi-server support | Yes | Yes |
| Best for | High-performance applications | Distributed systems |
HybridCache is not intended to replace Redis. Instead, it provides a cleaner programming model while allowing Redis to remain the distributed cache.
Creating an ASP.NET Core Project
Create a new Web API.
dotnet new webapi -n HybridCacheDemo
Install the Redis package.
dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis
Configure Redis.
{
"ConnectionStrings": {
"Redis": "localhost:6379"
}
}
Configuring HybridCache
Register HybridCache and Redis.
using Microsoft.Extensions.Caching.StackExchangeRedis;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration =
builder.Configuration.GetConnectionString("Redis");
});
builder.Services.AddHybridCache();
var app = builder.Build();
app.Run();
The application now supports HybridCache backed by Redis.
Implementing a Repository
Assume a repository fetches product information.
public class ProductRepository
{
public async Task<Product> GetByIdAsync(int id)
{
await Task.Delay(500);
return new Product
{
Id = id,
Name = "Laptop",
Price = 950
};
}
}
The delay simulates an expensive database operation.
Using HybridCache
Inject HybridCache into your service.
public class ProductService
{
private readonly HybridCache _cache;
private readonly ProductRepository _repository;
public ProductService(
HybridCache cache,
ProductRepository repository)
{
_cache = cache;
_repository = repository;
}
public async Task<Product> GetProductAsync(int id)
{
return await _cache.GetOrCreateAsync(
$"product:{id}",
async token =>
{
return await _repository.GetByIdAsync(id);
},
expiration: TimeSpan.FromMinutes(10));
}
}
Why This Approach?
Instead of writing:
Check memory cache
Check Redis
Query database
Save to both caches
HybridCache performs these steps through a single API, reducing repetitive caching code and making cache management easier.
Using Redis Directly
The equivalent Redis implementation is more manual.
Join the conversation! Your thoughts help the community grow.