A library provides IQueryable results caching using IMemoryCache or IDistributedCache.
Setup with DI
services.AddLoreCache(options =>
options
.UseCache<DistributedCache>()
.UseEntityFramework());
...
app.UseLoreCache();
Or Setup with static class
CacheManager.Cache = new MyCacheImplementation();
CacheManager.CacheKeyFactory = new MyCacheKeyFactory();
By default, all types from Include and ThenInclude methods are used as cache tags.
Cache keys are generated by CacheKeyFactory class implementation.
var results = context.Blogs
.Include(x => x.Posts)
.ToCachedListAsync(cancellationToken);
var results = context.Blogs
.Include(x => x.Posts)
.Where(x => x.Id == request.Id)
.CachedFirstOrDefault(cancellationToken);
By EF change detector extension. It invalidates all cache linked to default query tags.
await context.ChangeTracker.ExpireEntitiesCacheAsync();
Manual cache invalidation
CacheManager.ExpireTagsAsync(new List<string> { "tag_1" });