Entity  Framework Wrappers – Part 2 – AppFabric and "effective caching" with EF  integration aka "second level caching with EF" – simplified!
    
Problem statement: I want my SQL data to be cached in a way  where my EF calls still work seamlessly without doing any major code change but  the data is retrieved either from SQL store or a cache store if it's cached  already. Also if the data is updated in my DAL layer using EF context.save()  methods, it should invalidate the cache store automatically for that entity.
Solution: Use EF wrappers "http://efwrappers.codeplex.com/"  and use caching provider toolkit
Rough diagram for understanding how it works (before/after):
Before:
After:
Description:
The way it works is every simple. With EF  wrappers we get to create a new entity connection in the extended object  context class. The new improved entity connection executes the T-SQL query  generated by LINQ TO ENTITIES code against either the SQL store OR the app  fabric. 
For SQL store to understand the t-sql query  is fine but for appfabric (or any other cache store) cannot understand the  t-sql lingo :)  ??? 
Bingo! The EF caching wrapper classes [EFCachingCommand.cs]  creates the required methods for executing DB readers etc and before going to  SQL store a small code snippet like below is injected :) which checks if the cache is  already having the required result set OR entity object or anything :)
Required components:
Windows App Fabric Server (installed, configured and  running) OR Azure [I haven't tried with azure yet]
VS 2010 or above
A SQL database
Reference material:
A working solution attached in zip file:Link
Original article: http://msdn.microsoft.com/en-us/magazine/hh394143.aspx


 
 
No comments:
Post a Comment