Skip to content

mahdiprog/EntityFramework.Caching

Repository files navigation

EntityFramework.Caching

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 created based on EFCache introduced by Pawel Kadluczka but with a main difference. My main approach here is to cache database entites as well as query results. this approach reduce queries sending to DB many many more than caching just query results.

How to get it

You can get it from NuGet - just install the EF.Caching.Cache NuGet package

If you wanna use Memory as cache provider, add package EF.Caching.InMemory NuGet package

If you prefer to use Redis as cache provider, use package EF.Caching.Redis.StackExchange NuGet package or EF.Caching.Redis.ServiceStack NuGet package

How to use it

To make it work, just add EntityFrameworkCache.Initialize() method at app startup (before EF is used) and use proper config related to your cache provider:

In Memory:

EntityFrameworkCache.Initialize(new InMemoryCache());

Redis using ServiceStack library:

EntityFrameworkCache.Initialize(new ServiceStackRedisCache(new ServiceStackRedisCacheOptions
{
    Host = "localhost"
}));

Redis using StackExchange library:

EntityFrameworkCache.Initialize(new StackExchangeRedisCache(new StackExchangeRedisCacheOptions()
{
    Configuration = "localhost:6379"
}));

Releases

No releases published

Packages

No packages published

Languages