tags:

views:

283

answers:

2

What's an alternative to HttpContext.Current.Cache ?

I'm dealing with only the application tier and not the web tier so what is best for this?

We obviously don't want to use this because unit tests in the app tier will not have an HttpContext.

Would a simple list or dictionary object work?

+3  A: 

A simple list or dictionary object could work, as long as you don't mind the cache items never expiring (unless you write code to remove them the list/dictionary)- probably not a good solution unless you are only caching a small quantity of data. One solution to look into for non ASP.NET apps is the Enterprise Library Caching Application Block.

RichardOD
One strong recommendation if you take advantage of EntLib caching is I recommend writing an ICacheManager or similar interface to wrap EntLib and never directly interact with EntLib in your model incase you ever decide to switch to Memcache, velocity or any other caching provider. I also recommend that you use dependency injection for wiring up the cache manager class in your model, direct dependencies are extremely insidious.
Chris Marisic
This is exactly what I had done, thanks Chris!
LB
+2  A: 

I tend to work my hardest to not write any type of caching code. I leverage caching capabilities of other libraries such as StructureMap to handle both my dependency injection and caching needs. It provides a caching scope called Hybrid which will use ThreadLocal or HttpContext depending on where it's called from. It makes testing so much more effective.

Chris Marisic