ChangeTracker.Npgsql
1.0.2
dotnet add package ChangeTracker.Npgsql --version 1.0.2
NuGet\Install-Package ChangeTracker.Npgsql -Version 1.0.2
<PackageReference Include="ChangeTracker.Npgsql" Version="1.0.2" />
<PackageVersion Include="ChangeTracker.Npgsql" Version="1.0.2" />
<PackageReference Include="ChangeTracker.Npgsql" />
paket add ChangeTracker.Npgsql --version 1.0.2
#r "nuget: ChangeTracker.Npgsql, 1.0.2"
#:package ChangeTracker.Npgsql@1.0.2
#addin nuget:?package=ChangeTracker.Npgsql&version=1.0.2
#tool nuget:?package=ChangeTracker.Npgsql&version=1.0.2
ChangeTracker
Change Tracker is a library for efficient HTTP caching using database change tracking. It implements 304 Not Modified responses by generating ETags based on database timestamps, reducing server load while ensuring clients always receive current data.
Overview
ChangeTracker monitors database changes and generates ETags that combine:
- Assembly write time (when your application was built)
- Database timestamp (last data modification time)
- Custom suffix (optional runtime context)
When a client requests data with a cached ETag, the server compares it with the current state.
- If unchanged: it returns 304 Not Modified and the client uses its cached copy.
- If changed: fresh data is returned with a new ETag.
ETags follow this format:
{AssemblyWriteTime}-{DbTimeStamp}-{Suffix}
Ideal Use Case
- Read-heavy applications where data changes less frequently than it's read
- APIs serving semi-static data that changes periodically
- Applications needing reduced server load without compromising data freshness
Quick start
1. Enable table tracking
- PostgreSQL docs
2. Configure services
builder.Services
.AddTracker()
.AddNpgsqlProvider<DatabaseContext>();
3. Configure endpoint
Controller action:
[HttpGet]
[Track(["roles"])]
public ActionResult<IEnumerable<Role>> GetAll() => dbContext.Roles.ToList();
Minimal api:
app.MapGet("/roles/getall", (DatabaseContext dbContext) =>
{
return dbContext.Roles.ToList();
})
.WithTracking(options =>
{
options.Tables = ["roles"];
});
Middleware:
app.UseTracker(options =>
{
options.Tables = ["roles"];
options.Filter = (httpContext) => httpContext.Request.Path.Value.Contains("/api/roles/getall");
});
Verifying behavior
Testing Cache Hits
- Open your application in a browser
- Open Developer Tools (F12)
- Navigate to the Network tab
- Refresh the page
Cached responses will show:
- Status: 304 Not Modified
- Request Header: if-none-match (with ETag value)
- Response Header: etag (current ETag)
Testing Cache Misses
To test the full request pipeline:
- Open Developer Tools → Network tab
- Check "Disable cache" in the toolbar
- Refresh the page
This prevents the browser from sending if-none-match, forcing a cache miss and full server execution.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ChangeTracker.Core (>= 1.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.ObjectPool (>= 10.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.0)
-
net8.0
- ChangeTracker.Core (>= 1.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.ObjectPool (>= 8.0.22)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.11)
-
net9.0
- ChangeTracker.Core (>= 1.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.11)
- Microsoft.Extensions.ObjectPool (>= 9.0.11)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.