Support Caching and SqlCacheDependencies (or other second-level cache solution) as a built-in Feature
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Most web applications are "read mostly" meaning they query data much more frequently than they change it. This means they benefit immensely from caching. Back in 2005, ASP.NET introduced the SqlCacheDependency, which supported to modes of operation:
1) Triggers + Polling informed the application when changes occurred to a table that was being cached
2) App subscribes to SQL Server and is notified when changes would impact a given query. Provides row/column level cache invalidation. This solution is far more efficient and works well with web farms.
This article briefly describes the feature:
https://docs.microsoft.com/en-us/previous-versions/aspnet/ms178604(v=vs.100)
These features provided dramatic performance improvements with minimal effort 17 years ago but have never been carried forward or made compatible with EF (nor EF Core) as far as I'm aware. I've requested this feature periodically since EF was created but so far without success.
I would like to be able to enable caching on a per-entity basis as part of EF configuration. This caching should automatically be updated when the underlying data changes, using one of the above techniques or some novel approach. I don't need every caching feature under the sun (durations, sliding windows, etc etc) - I just want to be able to reduce the number of needlessly repetitive queries on lookup tables and other read-mostly data.
## Why not do it myself?
I'm unaware of any hooks that allow changes to whether, when, an how EF chooses to issue queries to its data store. This is data-level caching, below the level of entities and change-tracking. If there are hooks that someone can use to add a `SqlCacheDependency` to a `SqlCommand` used by EF please show me and I'll gladly create a POC for doing this myself. I just don't think that low level implementation has ever been exposed for third party extensions.
Contributor guide
Assessment
This issue has not been assessed yet.