0

I want to use entity framework core ( or any other ORM for that matter ) that can use the sql server built in SQL DEPENDENCY so that each insert,update,delete from a table, fires a sql dependency event and refreshes the cache inside entity framework for that specific table.

In other words to put it simply, I have a 800 mb database, with 50 tables that only have one to many, many to one and one to one relations. I want to take all those tables and put them into memory as tables.

The entity framework context should be disposable and not live forever.

1 Answers1

1

You can use any ORM to retrieve data from the database. Once the data is retrieve from the database, you can set SQL dependency on the item before it is inserted in to the cache.

NCache provides its own implementation of SQL dependency independent of the framework used to retrieve database content (EF, NHibernate, ADO.NET etc.). In this feature, NCache registers SQL commands (SELECT queries and SELECT stored procedures) with the database server. If any UPDATE or DELETE event modifies the result set that can be retrieved with those registered SQL commands, then SQL server will send a notification to NCache in response will remove the corresponding cache data.

Therefore, inside the using block of the db context, you can add the content retrieved from database into the cache with the NCache SQL dependency set on it.

To allow for 100% update in cache data in response to UPDATE events instead of removing the affected cache data altogether, This involves integrating the auto-reload feature that utilizes the read-thru capabilities of NCache in the form of backing source providers. In this case, you can set a resync flag on the cache item to specify that NCache should retrieve fresh data in case the item is to be removed by SQL dependency For that, a read-thru provider will go ahead and retrieve the fresh data from the database and replace the outdated cache data. Read-thru providers together with write-thru providers constitute the NCache backing source providers that enables NCache to execute read and write commands to the database on the clients' behalf.

More information about SQL dependency can be found at the following link:

http://www.alachisoft.com/resources/docs/ncache/prog-guide/sql-dependency.html

Information about the NCache backing source providers can be found at the following link:

http://www.alachisoft.com/resources/docs/ncache/prog-guide/data-source-provider.html

Shoeb Lodhi
  • 156
  • 1
  • 2