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?
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:
|Features||EF Plus||EF Extented||EF Cache|
|Tags & Expiration|
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
I'm the library owner.
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.
The library is very recent
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
The library has everything you need from a caching library and support more features: audit, batch operations and query future.
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.
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
Good library with a good support within a few days. The library is the only one working also with interceptor.
The lack of documentation make it very hard to understand how to use the library and what you can do with it.
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.
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?