13

The NHibernate documentation and the book NHibernate In Action state that the cache provider NHibernate.Cache.HashtableCacheProvider is not intended for production use. However, I could not find a reason for this. Does anyone know the reason?

Marco Eckstein
  • 4,448
  • 4
  • 37
  • 48

1 Answers1

12

Because it doesn't support any kind of reasonable caching semantics (first example that comes to mind: timeouts), and it basically grows indefinitely.

It's intended for testing only, as it just provides the simplest possible implementation of a local cache.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • 6
    "A cache with a bad policy is another name for a memory leak." http://blogs.msdn.com/b/oldnewthing/archive/2006/05/02/588350.aspx – codekaizen Nov 28 '10 at 19:49
  • Thanks! The indefinite growth is already enough reason for me to not use it in my application. However, could you please further elaborate the reasonable caching semantics/ timeout issue? And what exactly is meant with testing - "true" testing (unit testing etc.) or just some ad hoc "play around" testing? – Marco Eckstein Nov 28 '10 at 20:08
  • @Marco: the cache must be able to optimize the usage of limited resources (memory) by prioritizing, handling dependencies, expiration... HashtableCache is enough for unit testing (for example, asserting that calling the same repository method twice results in just one DB call). It's also great for playing around because it's predictable. – Diego Mijelshon Nov 28 '10 at 21:31