views:

30

answers:

1

Hi All, I've been using NHibernate for a while now, I'm still wondering what the differences are between the the Second Level Cache Providers ?

  • Do some perform better\worse ?
  • What is popular and why ?

For claraty I'm talking about

  • NHibernate.Caches.MemCache
  • NHibernate.Caches.Prevalence
  • NHibernate.Caches.SharedCache
  • NHibernate.Caches.SysCache
  • NHibernate.Caches.SysCache2
  • NHibernate.Caches.Velocity

and I'm sure there are others.

Thanks

+2  A: 

The most important thing you need to know about 2nd-level NHibernate caches is that if your application depends on a 2nd-level cache to perform adequately, you're doing something wrong.

Other than that, comparing these cache providers effectively boils down to comparing memcached vs prevalence vs Velocity, etc, and that is not really related to NHibernate.

Here are some reasons (by no means a complete list) to pick one over the others:

If you want to keep it simple and don't run your app in a farm, you might want to use SysCache/Prevalence, which runs in-proc. If you use MS SQL Server, use SysCache2.

If you need a huge cache across many cache-dedicated servers, you might want to use memcached, which can run on Linux so you'd avoid licensing costs.

If your application runs on Azure or already uses AppFabric, you might want to use Velocity.

Mauricio Scheffer
I disagree with the first paragraph. Some scenarios can be hell without caching, no matter how you code them. And the alternative is usually some form of manual caching, which is usually worse for the architecture.
Diego Mijelshon
@Diego: granted, it's an arguable point. I prefer doing "manual caching" in a higher layer to embrace more than data access in the cache (e.g. heavy processing / web services). This manual caching is 99% of the time a decorator or a proxy, so it doesn't add too much overhead to the architecture.
Mauricio Scheffer
@Diego: BTW this would make an excellent topic for a blog post "NH 2nd-level cache: what it is and when/why/how to apply it" ;-)
Mauricio Scheffer
Added to my ToDo list for the blog ;-) Regarding higher-level caching, it depends on WHAT you're caching, IMO. It certainly makes sense to cache responses or high-level graphs, but entities are problematic.
Diego Mijelshon
Nice summary, I agree with you about not depending on the cache all of the developers here are required to develop with the 2nd level cache off.We don't have a farm but its likely in the future we do run MS SQL Server so I'll have a look at these 3 options and see which works for me.Thanks
Saint Gerbil