Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

I think you can take a loot at Velocity project.

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

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.

The System.Runtime.Caching.MemoryCache is recommended by Microsoft in lieu of System.Web.Caching. It can be used in the context of the MS Caching Application Block suggested by Abhijeet Patel.

See:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top