0

we're working on a project which developed with ASP.net MVC technology and based on the layered architecture; in addition, we use ADO.Net to fetching data by SQL Store Procedures and generating object models in "DataAccess" Layer (I know this is an old technology to fetch data, but we couldn't migrate to EF or other ORMs).

our Architecture Diagram

we decide to cache some cacheable Object models which inherited "Icacheable" Interface, yet we don't want to cache the objects forever(until the application is working); in fact, we just need to cache them during a request and after that dispose of cached objects.

In here there are two questions?

1) which layer is better for doing this caching? Repository or DataAccess(or maybe other layers!)?

2) how to we could do this?

  • **1 -** your ORM might already have cache features, NHibernate, EntityFamework, etc have cache enable calls, so if you're asking the same query from the db connection, you will get the result from cache and not from a call to the db again ... this is well seen when you use [`.Find()`](https://stackoverflow.com/a/21708443/28004) **2 -** if you want to leveradge your own caching, [check my answer on it](https://stackoverflow.com/a/14047758/28004). – balexandre Sep 10 '17 at 10:36
  • we use own ORM, and it isn't EF or NHibernate. we fetch data from database and we make Model objects in DataAccess layer from fetched data. In general we need to cache this generated objects to use them during the request. – Azad Soleimani Sep 10 '17 at 11:13
  • then just read that second link after "Make room for any Cache system" ... it shows you how to create and use a cache system and you can then apply how do you want to store, in my example I'm using `HttpRuntime.Cache` but you can use whatever you want, in production I would use memcache or redis... – balexandre Sep 10 '17 at 11:25

0 Answers0