7

I want to use EntityFramework.Cache for one of my tables, but I can not find any information about how does it work with live data and relationships?

I want to know if I add some data to my table or the relation tables does it understand it and re-cache table again or the result could be stale?

Does anyone work with any Entity Framework second level cache?

1

1 Answer 1

10

A cache normally caches entities (Detached from the context) and re-uses the same result as long as the cache is not expired.

If you change the query, a new result is cached (even if it returns the same entity key) since relations could have been changed.

Here is an alternative to the cache you are currently using:

Disclaimer: I'm the owner of the project EntityFramework Plus on GitHub

EF+ Query Cache allows to cache query with tag, expiration and cache control.

Documentation: Entity Framework - Second Level Cache

EDIT: Answer comment

if data has been updated, and new information must be served up that we can remove specific entities from cache

For EF6, we have the built-in IsAutoExpireCacheEnabled option:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    QueryCacheManager.IsAutoExpireCacheEnabled = true;
}

For EF Core, we didn't find out how to make it happen yet.

3
  • Nice! Is there a way to share Cache between Context Instances?
    – user756037
    Apr 9, 2021 at 21:54
  • @user756037, if you talk about the EF+ Query Cache, it already works between context instances since items are detached. Apr 10, 2021 at 15:42
  • @JonathanMagnan Does this enable granular cache invalidation? It's vitally important for reliability if data has been updated, and new information must be served up that we can remove specific entities from cache. Jan 10, 2022 at 3:01

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.