views:

156

answers:

4

I need a cache that responds to memory pressure like the one build-into ASP.NET. I'm not using a web site, however, I'm building a Windows Service.

Any suggestions? (code, techniques, products, I don't care as long as it's in-memory)

+8  A: 

If you're familiar with the ASP.NET Cache (System.Web.Caching), you can still reference and use it, even if you're not running within a web application.

Nader Shirazie
You can access it via System.Web.HttpRuntime.Cache (static property)
Richard Szalay
I can't beat that.
Jonathan Allen
Man that is non-obvious. I tried to use it today and both "HttpContext.Current.Cache" and "New Cache" were failing without telling me why. Of course the non-obvious HttpRuntime.Cache worked like a champ.
Jonathan Allen
Agreed. But HttpContext.Current will always be null if you're not processing an ASP.NET request.
Nader Shirazie
+1  A: 

Have you looked at the Microsoft Enterprise library Caching Block:

"Nearly every application needs to cache data. While you're probably familiar wth the caching functionality built into ASP.NET, the Enterprise Library Caching Block provides in-memory, file-based, or database caching storage for all your other .NET applications. "

Caching App Block

Jay
+2  A: 
Mehmet Aras
Velocity is an out-of-process option. That makes it great for server farms, but silly for an application that will one have one running instance world-wide.
Jonathan Allen
I listed it as an option so that you are at least aware of your otions. It is up to you to evaluate and eliminate based on your requirements, cost-benefit analysis, and thought process. After all, it is hard to determine what's silly or not about an application given just a couple of sentences. Also keep in mind, it is out-of-process but in memory. It may be nice to find things already cached in memory when your application starts up.
Mehmet Aras
+1  A: 

memcached has clients for .Net:

Remus Rusanu