views:

279

answers:

3

I have an ASP.net application that uses some common business object that we have created. These business objects are also used in a few other windows services or console applications.

The problem I am running into is that if I have a class "foo" and a class "bar" and each has a function loadClient(), if I call foo.loadClient() and bar.loadClient(), each request will hit the database. I figure implementing some sort of cache would reduce unnecessary round trips to the DB.

Here's the catch. I want the cache to be specific to each HTTP request that comes in on the ASP.net App. That is, a new request gets a brand new cache. The cache can exist for the lifetime of the other console applications since 90% of them are utilities.

I know I can use System.Web.Cache but I don't want my middleware tied to the System.Web libraries.

Hope that explains it. Can anyone point me in the right direction? Thanks!

A: 

If you are looking for interprocess caching then thats difficult.

But if you dont want your middleware tied to System.Web then you can write one interface library that will serve as bridge between your middleware and system.web.

In future if you want to tie it to other cache manager then you can just rewrite your bridge interface library keeping your middleware absolutely independent of actual cache manager.

Akash Kava
+1  A: 

Are you reusing objects during the lifetime of a request? If not,then the model you have suggests that each postback will also create a new set of objects in effect obviating the need for a cache. Typically a cache has value when objects are shared across requests

As far as using a non web specific caching solution I've found the Microsoft Caching Application Block very robust and easy to use.

Abhijeet Patel
Thanks. I'll take a look at the MS Caching Application Block. We do enable some use of System.Web.Cache. However, there is some stuff we want pulled from the DB on each request, especially in the middle tier. If one request is doing 5 different actions and each one of those actions loads the same object from the DB, I'm would want that object loaded from the DB once.We have a load-balanced set of web servers so loading an object from the DB multiple times in that one request could load inconsistent data.
Jonathan
+1  A: 

I think you can take a loot at Velocity project.

http://msdn.microsoft.com/en-us/data/cc655792.aspx - there is a brief article

Andrei Taptunov