Entity Framework Cache Provider
The ADO.NET Entity Framework is a popular object-relational mapping framework. It provides abstraction from the underlying relational data that is stored in a database and presents its conceptual schema to the application.
In most of the high transaction cases, the database quickly becomes a bottleneck because in a database tier, adding more and more servers cannot scale performance. To achieve this scalability, use in-memory cache provider module along with Entity Framework application. Entity Framework does not provide a Second Level Cache provider model but it is flexible to support second Level Cache Provider. Entity Framework Caching Provider.
NCache has implemented a custom ADO.NET provider called an "Entity Framework Caching Provider" which acts between Entity Framework and the original provider. NCache provides the features listed below:
- No Code Change: NCache Entity Framework Caching Provider can be integrated in application without any code change.
- Better Performance: NCache custom provider intercepts all the database queries calls and puts result-sets of queries in a cache storage. This increases the performance of applications by avoiding expensive databases trips.
- Application Scalability: NCache provides a reliable and shared memory resource for storage. It gives the ability for sharing transactional context between different entities in any entity framework application.
The caching provider can perform various functions, such as:
- Managing connections, commands, transactions and data readers.
- Monitoring queries and commands before they execute.
The following figure shows how and where NCache Entity Framework Provider plugs into an Entity Framework application.
Entity Framework Caching Integration Modes
There are two execution modes for NCache Entity Framework Caching Provider:
- Analysis mode
- Caching mode
These modes are mutually exclusive, so NCache Entity Framework Caching Provider cannot execute in both modes at the same time. It can either be in "Caching" mode or in "Analysis" mode.
Recommendation: First execute the entity framework application within analysis mode of NCache Entity Framework Caching Provider.
- Analysis Mode
Analysis mode is a pass-through mode; no caching is done at this mode. This mode provides features that are listed as follows:
Monitoring Query: Monitoring the number of times each query is executed by Entity Framework Application. This allows the user to determines which queries are most frequent and are the best candidates for caching.
Generate Reports: It generates reports for queries with proper syntax and also arranging them in descending order. That allows the user to choose suitable queries and copies them for caching.
- Caching Mode
This mode is basically designed for the actual use of NCache in Entity Framework applications. At this point, queries and their result sets are cached. Caching mode only entertains those queries which are given in configuration file i.e. efcaching.ncconf.
In This Section
Using NCache as Entity Framework Second Level Cache
Explains how to configure and use NCache as Entity Framework second level cache.
Entity Framework-Caching Configuration File
Explains the changes required in EFcaching.ncconf to run the Entity Framework application in NCache.