6

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)

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

4 Answers4

11

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
  • 10,736
  • 2
  • 37
  • 43
  • 3
    You can access it via System.Web.HttpRuntime.Cache (static property) – Richard Szalay Aug 14 '09 at 21:07
  • 1
    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 Sep 30 '09 at 17:19
  • Agreed. But HttpContext.Current will always be null if you're not processing an ASP.NET request. – Nader Shirazie Sep 30 '09 at 20:41
  • 2
    .Net 4.0 has "object caching" now so you don't have to rely on the System.Web library version. See http://deanhume.com/Home/BlogPost/object-caching----net-4/37 – Jon Adams Oct 20 '11 at 02:45
2
Mehmet Aras
  • 5,284
  • 1
  • 25
  • 32
  • 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 Aug 18 '09 at 20:14
  • 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 Aug 18 '09 at 21:47
1

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,644
  • 1
  • 30
  • 55
1

memcached has clients for .Net:

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569