EF Core 10 has no built-in second-level cache — the change tracker is only a first-level identity map. EFCoreSecondLevelCacheInterceptor v5.5.0 fills that gap by intercepting queries and caching results keyed by SQL. In v5, cache providers are separate NuGet packages (MemoryCache, StackExchange.Redis, or HybridCache). Setup involves installing the right provider, registering it in Program.cs, and adding the interceptor to DbContext. Queries can be cached per-query with .Cacheable() or globally with CacheAllQueries(). Benchmarks show in-memory hits are ~11x faster than a DB round trip; Redis hits are ~2.5x faster. Auto-invalidation only works for SaveChanges — ExecuteUpdate, ExecuteDelete, raw SQL, and external writes bypass it and require manual invalidation via IEFCacheServiceProvider, with the correct cache key prefix. In-memory caches are per-instance, so multi-instance deployments need Redis. Multi-tenant apps risk key collisions unless the tenant ID is a real SQL parameter and per-tenant key prefixes are used. Best suited for read-heavy reference data; avoid for volatile, per-user, or compliance-sensitive data.

18m read timeFrom codewithmukesh.com
Post cover image
Table of contents
EF Core Interceptors: The Complete GuideWhat Is Second-Level Caching in EF Core?Tracking vs. No-Tracking Queries in EF Core 10Does EF Core Have a Built-In Second-Level Cache?How Do I Add Second-Level Caching in EF Core 10?How Do I Use Redis as a Second-Level Cache?HybridCache in ASP.NET CoreSecond-Level Cache Benchmark: How Much Does a Hit Save?Why Does a Cached Query Return Stale Data?Bulk Operations in EF Core 10Global Query Filters in EF CoreWhen Should You Not Use Second-Level Caching?10 EF Core Performance Mistakes (and How to Fix Them)Second-Level Cache vs HybridCache vs Manual CachingIn-Memory Caching in ASP.NET CoreHow Do I Verify the Cache Is Actually Hitting?Distributed Caching in ASP.NET Core with RedisKey TakeawaysTroubleshootingFAQSummary
3.4K Impressions