views:

194

answers:

1

I'm using both IBatis.NET and Spring.NET on a project at work and I'd like to figure out if I can leverage both/either frameworks to achieve "per-request caching" on all calls into my DAL layer. In other words, every time an HTTP request is served by ASP.NET, I would like first call into a DAL method to hit the remote DB, but all calls thereafter to be inflated from cache.

I've seen a few articles describe a way to achieve this using HttpContext.Current, but I can't stomach the idea of polluting my DAL layer with System.Web references. I'd also like to leverage these frameworks if at possible as I'm not fond of re-inventing the wheel.

+2  A: 

I'm no expert on IBatis.NET and integration with Spring.NET most likely more thank lacking but here goes..

I would create a custom ICache implementation that uses HttpContext.Current.Items. Then I would make DAL layer objects proxied with Spring.NET AOP (they are behind interfaces, aren't they?). Then it's just a matter of applying the cache advice using the AOP framework.

You should be able to do this by following Spring.NET documentation about AOP caching and implement the ICache using Spring.NET's ASP.NET cache implementation as starting point.

Marko Lahma