Repository pattern & Unit-Of-work pattern with SLC-EF6.1

Feb 10, 2015 at 8:39 AM

I have created the small application using ASP.NET Web2API using repository pattern and unit of work pattern. As the performance of application depends on the DB and most of the data is 'read-only from user's side, i wanted to use some kind of cache to save the round-trip to DB.

Could someone discuss about how the SLC can be used in repository pattern? Will each instance of DB context created for a unit-of-work will have its own cache? I have some data-tables that are 'read-only' for most of the application's life (for #months) and would like to get some real zero delay access to them.

Thanks and Regards,
Amit Rangari
Feb 10, 2015 at 6:25 PM
Hi Arangari,

It depends a little bit on the cache implementation. The InMemoryCache that ships with the NuGet package is using a static dictionary which means that the cache will be bound to the AppDomain used by your app. As a result the lifetime of DbContext instances does not matter - results for any query will be subject to caching as per rules defined by the caching policy. In this case the results will be lost if the application exits. If you need to persist results across application restarts you can use a different implementation of caching mechanisms for the second level cache - there is one that uses (Redis)[] and one that uses (Dache)[] (I personally have tried neither though).

Hope this helps,
Feb 26, 2015 at 2:57 PM
Edited Feb 26, 2015 at 2:59 PM
Hi Pawel,

thanks for the input. I was not able to respond earlier.

I will explore these...