HyperCache is a lightweight and efficient caching solution built on the simple implementation of the Delta NuGet Package (Delta). This project demonstrates the integration of modern technologies, including .NET 9.0, Entity Framework Core 9.0, Blazor, MSSQL, and Code-First database design patterns.
HyperCache is developed in Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview and aims to provide a seamless, high-performance caching mechanism for .NET applications. By leveraging Entity Framework Core's Code-First approach and Blazor's modern UI framework, the project provides a robust and scalable solution for handling caching with SQL Server.
- .NET 9.0: Utilizes the latest advancements in the .NET framework for improved performance and productivity.
- Entity Framework Core 9.0: Implements Code-First database design for flexibility and maintainability.
- Blazor: Builds modern and interactive UI components.
- Delta NuGet Package: Provides a simple and effective caching implementation.
- MSSQL: Ensures data persistence with SQL Server.
- Scalable Architecture: Designed for ease of use and scalability in enterprise environments.
Metric | Before Implementation (1M Rows) | After Implementation (1M Rows) |
---|---|---|
Total Requests | 10 | 14 (Demonstration Purpose) |
Request Method | GET | GET |
Initial Request Time (s) | 3.58s - 3.67s | 5.90s (Due to first-time data retrieval, cache index setup, and rowversion tracking) |
Subsequent Request Times (ms) | 3.58s - 3.67s | 58ms, 12ms, 9ms, 7ms, 6ms, 7ms, 9ms, 6ms, 8ms |
Total Data Transferred (KB) | 9.3 KB | 7.2 KB |
Status Code Consistency | 200 OK | 200 OK |
Protocol Used | h2 | h2 |
Follow these steps to set up the HyperCache project:
-
Clone the repository:
git clone https://github.com/biswajitpanday/HyperCache.git cd HyperCache
-
Open the project in Visual Studio Enterprise 2022.
-
Restore the required NuGet packages:
- Delta
- Entity Framework Core 9.0 etc.
NuGet package restoration can be performed by running:
dotnet restore
-
Configure the connection string in the
appsettings.json
file to point to your MSSQL instance:"ConnectionStrings": { "DefaultConnection": "Server=YOUR_SERVER_NAME;Database=HyperCacheDb;Trusted_Connection=True;" }
-
Apply the database migrations:
dotnet ef database update
-
Build and run the project:
dotnet run
-
Build and run the Blazor UI: Use Blazor components for interactive user interfaces.
To properly configure and use the Delta package in HyperCache, follow these steps:
In your AppDbContext.cs
file, configure the RowVersion
column for delta tracking:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var customProperty = modelBuilder.Entity<CustomProperty>();
customProperty.HasKey(cp => cp.Id);
// Configures RowVersion for Delta Package
customProperty
.Property(cp => cp.RowVersion)
.IsRowVersion()
.HasConversion<byte[]>();
}
Ensure the Delta package is registered before mapping controllers:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddControllers();
// Register Delta middleware
builder.Services.AddDelta<AppDbContext>();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
// Enable Delta middleware
app.UseDelta<AppDbContext>();
app.MapControllers();
app.Run();
Ensure the CustomProperty
entity includes a RowVersion
column:
public class CustomProperty
{
public int Id { get; set; }
[Timestamp] // Required for EF Core concurrency tracking
public byte[] RowVersion { get; set; }
}
- Before implementation, all requests took 3.58s to 3.67s consistently.
- After implementation:
- Initial request took 5.90s (higher due to potential caching setup or data fetch).
- Subsequent requests were drastically faster, reducing to milliseconds (58ms, 12ms, 9ms, etc.).
- Total data transferred reduced from 9.3KB to 7.2KB, optimizing performance.
-
Significant Performance Boost
- Reduces response time for subsequent queries by using caching and delta updates.
- Greatly beneficial when dealing with large datasets (e.g., 1,000,000+ rows in MSSQL).
-
Optimized Data Transfers
- Avoids redundant data retrieval.
- Transfers only changed (delta) data, reducing bandwidth usage.
-
Scalability & Efficiency
- Improves the efficiency of real-time applications.
- Enhances batch processing and event-driven architectures.
✅ Best use cases:
- Large databases with millions of rows where full queries take excessive time.
- Applications requiring frequent data updates (e.g., financial transactions, inventory tracking).
- Microservices architecture where only modified records need to be fetched.
- API-driven applications that fetch data dynamically and require faster response times.
❌ Avoid using Delta when:
- Small datasets (e.g., tables with a few thousand records).
- One-time data fetches where changes are infrequent.
- Use cases requiring complete data consistency instead of just delta updates.
- Complex queries where keeping track of delta changes adds significant overhead.
This implementation proves highly effective for large-scale applications and reduces the load on MSSQL databases, making it a must-have for performance-driven applications.
Contributions are welcome! If you want to improve the project, follow these steps:
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Submit a pull request.
This project is licensed under the MIT License.
For any queries or suggestions, feel free to contact the repository owner:
- GitHub: biswajitpanday