Skip to content
github-actions[bot] edited this page May 26, 2026 · 2 revisions

CleverCache

CleverCache solves the problem of remembering when to invalidate cache entries when the underlying data changes — especially when a single cache entry contains data from multiple entity types.

With a small amount of configuration, CleverCache automatically tracks changes via EF Core and clears related cache entries when any tracked entity is created, updated, or deleted.

Documentation

Topic Description
Getting Started Install, configure EF Core interceptor, register services
Caching Data GetOrCreate, multi-type associations, entry options
Cache Providers Memory, distributed, Redis, custom providers
Dependent Caches AddKeyToType, AddDependentCache, [DependentCaches] attribute
MediatR Integration [AutoCache], [InvalidatesCache], pipeline setup
Bulk Operations Handling ExecuteDelete/ExecuteUpdate and non-EF writes
Diagnostics Inspecting the dependency graph and tracked keys at runtime
Unit Testing FakeCache, mocking ICleverCache
Migrating to V2 Breaking changes and before/after examples for V1 → V2

Packages

Package NuGet Purpose
CleverCache NuGet Core package
CleverCache.EntityFrameworkCore NuGet EF Core interceptor and DbSet scanning
CleverCache.MediatR NuGet MediatR pipeline behaviours
CleverCache.Redis NuGet Redis cache provider

EF Core. Automatic invalidation via SaveChanges requires the CleverCache.EntityFrameworkCore package. Without EF Core you can still use CleverCache for manual invalidation — see Bulk Operations.

Clone this wiki locally