https://github.com/moozzyk/EFCache
Second Level Cache for Entity Framework 6.1
https://github.com/moozzyk/EFCache
c-sharp caching entity-framework hacktoberfest
Last synced: 7 months ago
JSON representation
Second Level Cache for Entity Framework 6.1
- Host: GitHub
- URL: https://github.com/moozzyk/EFCache
- Owner: moozzyk
- License: ms-pl
- Created: 2016-11-20T20:52:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-27T00:45:18.000Z (about 2 years ago)
- Last Synced: 2025-04-19T03:10:30.732Z (7 months ago)
- Topics: c-sharp, caching, entity-framework, hacktoberfest
- Language: C#
- Homepage:
- Size: 143 KB
- Stars: 101
- Watchers: 14
- Forks: 22
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
- awesome-entity-framework-6 - EFCache - EntityFramework.Cache provides a second level cache for Entity Framework 6.1 and newer. (Supported Packages)
README
# Second Level Cache for Entity Framework 6.1+
Entity Framework does not currently support caching of query results. A sample EF Caching provider is available for Entity Framework version 5 and earlier but due to changes to the provider model this sample provider does not work with Entity Framework 6 and newer. This project is filling the gap by enabling caching of query results for Entity Framework 6.1+ applications.
#### This project was moved from https://efcache.codeplex.com
You may still find some useful information there:
- Old discussion board - https://efcache.codeplex.com/discussions
- Issues - https://efcache.codeplex.com/workitem/list/basic
# How to get it
You can get it from NuGet - just install the [EntityFramework.Cache NuGet package](http://www.nuget.org/packages/EntityFramework.Cache)
# How to use it
The project uses a combination of a wrapping provider and a transaction interceptor. A simple [InMemoryCache](https://github.com/moozzyk/EFCache/blob/master/src/EFCache/InMemoryCache.cs) is included in the project. To use it you need first configure EF using code based configuration. Here is an example of how such a configuration looks like.
```C#
public class Configuration : DbConfiguration
{
public Configuration()
{
var transactionHandler = new CacheTransactionHandler(new InMemoryCache());
AddInterceptor(transactionHandler);
var cachingPolicy = new CachingPolicy();
Loaded +=
(sender, args) => args.ReplaceService(
(s, _) => new CachingProviderServices(s, transactionHandler,
cachingPolicy));
}
}
```
Starting with version 1.1.1 you can also use the new static `EntityFrameworkCache.Initialize()` method to configure EF to use EFCache. The `Initialize` method should be invoked at app startup (before EF is used) - e.g. in the application static constructor. To initialize EFCache with the built-in [InMemoryCache](https://github.com/moozzyk/EFCache/blob/master/src/EFCache/InMemoryCache.cs) you can use the following code:
```C#
EntityFrameworkCache.Initialize(new InMemoryCache());
```
You can find more details in my [blogpost](http://blog.3d-logic.com/2014/03/20/second-level-cache-for-ef-6-1/)