0

We are using EF code first with the App Fabric cache on Windows Azure (although, I think the question is really more generic since we are using it as an ASP.net caching provider). Is there an easy way to enable caching of DBset objects? Our db is small and not updated very frequently, so ideally we could cache the entire database in memory, and use some ttl expiry to refresh object sets. Any advise from someone with experience caching using EF code first would be great.

Ladislav Mrnka
  • 349,807
  • 56
  • 643
  • 654
Birdman
  • 859
  • 2
  • 10
  • 14

2 Answers2

3

Don't do that. If you want to cache data, extract them to separate Lists and cache them separately. Caching DbSet means caching DbContext which I would promote to anity-pattern in Entity framework. Problems with identity map and unit of work are described in linked answer. Another problem is that there is no real refresh. If you really want to refresh data you must dispose context and create a new one. Context is also not thread safe so sharing it among multiple requests can cause unexpected results.

Community
  • 1
  • 1
Ladislav Mrnka
  • 349,807
  • 56
  • 643
  • 654
0

Maybe you could use this solution, but I never used it with Azure:

EF Caching Provider

Niels Ziegler
  • 436
  • 2
  • 6
  • 14