Introduction

One of the easier way to optimize an application performance is using a cache for rarely modified entities like states & countries which dramatically reduce the number of round-trip to the database.

The concept to create a second level cache in Entity Framework or any other ORM is very simple. The first time a query is invoked, data are retrieved from the database and stored in the cache before being returned. All future calls will retrieve data from the cache until it expired to avoid making a database round-trip.

So what are the available options until Entity Framework support a built-in second level cache?

Solution

Using a third party library supporting second level caching in Entity Framework. A lot of Free & Open source library can be found supporting caching but essentially there is only a few major libraries worth talking.

In this article, we will compare the following libraries:

Example


Comparison

Features EF Plus EF Extented EF Cache
Price FREE FREE FREE
Support
Query Deferred
Tags & Expiration
Cache Expiration
Custom Provider
EF6
EF Core

Query Deferred

Immediate method like all, any, count, first, last cannot be cached unless using a library supporting deferred query.

Tags & Expiration

Tagging the cache lets you expire later on all cached entries with a specific tag by calling the "ExpireTag" method.


Entity Framework Plus

Disclaimer

I'm the library owner.


Pros

The library has everything you need from a caching library, including documentations and an outstanding support. It’s the only library supporting all version of Entity Framework (EF5, EF6, EF Core) and query deferred.

Entity Framework Plus contains also a lot of more features: audit, batch operations, query future, query filter, query include filter, etc.

Cons

The library is very recent

Discussion

The library is young but it’s also an advantage since it has been built by looking at what other libraries fail to support to overcome their limitations. The library is available as a whole package with other features or as a standalone version.


Entity Framework Extended


Pros

The library has everything you need from a caching library and support more features: audit, batch operations and query future.

Cons

The library is unsupported. The library owner haven’t answered any issues & questions from users for several months and nothing is under development from Entity Framework Core.

Discussion

Entity Framework Extended is a well-known library and very old library. We can assume it safe to use the caching features without problem however, some people have reporting some high level bug like key not being unique which bring incorrect data.


Entity Framework Cache


Pros

Good library with a good support within a few days. The library is the only one working also with interceptor.

Cons

The lack of documentation make it very hard to understand how to use the library and what you can do with it.

Discussion

The project owner still supporting and answer question within a few days which is really good however the lack of documentations and examples make it very hard to getting started and to recommend.


Conclusion

Entity Framework Plus stand out from other libraries by already supporting Entity Framework Core and is the only one supporting query deferred. The library also contains a lot more features which can be useful for your project.

All library are Free & Open Source, so you have the option to try them all and get yourself your own opinion.


Share your experience

  • What's features is missing?
  • Which library are you using and why?