AdrienTorris
AdrienTorris

Reputation: 9391

Cache table with Entity Framework Core

I have a database (SQL Server for your information but I don't think it's very important) with some tables, and a ASP.NET Core web application who implements Entity Framework Core to manage data.

In my database, I have 4 tables who are very often used and joined to almost each requests, and the data in this tables are very rarely updated, si I would like to put them in cache to not fetch data in database each time, but only for this tables.

How can I do that with Entity Framework Core ?

I read the documentation but I didn't found anything about caching : https://docs.efproject.net/en/latest

Upvotes: 3

Views: 6130

Answers (3)

cemdev
cemdev

Reputation: 11

AFAIK, EF doesn't have caching. NHibernate however has excellent caching support. It's a little bit painful to have to use EF now instead of NHibernate, but NHibernate doesn't support Core quite yet.

Upvotes: 0

Dmitry
Dmitry

Reputation: 16825

I don't think you will be able to use "cached" table rows in your EF queries. You can cache tables (in redis, memory - any on your choice), but when you will make queries to your DB - you will need to perform additional manual processing in your code (in server memory) for joining results from EF with cached tables.

Upvotes: 0

Sampath
Sampath

Reputation: 65938

You can use StackExchange.Redis cache for that.You just need to store your tables data on it and invalidate it when tables will be updated.That is it.

Here is the Link : StackExchange.Redis

Upvotes: 1

Related Questions