Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 18 | Comments: 84

filter by tags archive

Deep Diving Into NHibernateThe Second Level Cache

time to read 2 min | 326 words

I mentioned before that I am now part of the NHibernate project, but so far I haven't done much with it. In what turns out to be a nice timing, I found a fairly obscure bug that I hope that I can fix, and I am going to bore you with all the nitty gritty details of how I am going to do it.

Before I can begin, let me describe what area I am going to work at.

NHibernate has two level of caches. The first level is the session, which holds all the entities that were loaded (or saved) with the session. This cache is not shared among threads/requests. This cache hold the objects as fully instansiated entities, which mean that sharing them among threads/requests will cause multi threading issues.

The second level cache is shared among all the session that were created from the same session factory (typically, you only have a single session factory per application, so in essense, this is an application level cache). There are several targets to this second level cache, but the most common are:

  • Hashtable cache (for debugging/testing purposes only)
  • SysCache - which utilize the ASP.Net Cache
  • Memcached - a distributed caching system

The second level cache does not hold entities, but collections of values. This means that you don't have to worry about mutli threading issues when you use this cache.

As far as I can see, the second level cache isn't very utilized in NHibernate projects, although I am not quite sure why this is the case, since it can give quite a performance boost to an application, without affecting the client code.

More posts in "Deep Diving Into NHibernate" series:

  1. (24 Jul 2006) The Tests Structure
  2. (24 Jul 2006) The Second Level Cache

Comments

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Buffer allocation strategies: A possible solution - 3 days from now
  2. Buffer allocation strategies: Explaining the solution - 4 days from now
  3. Buffer allocation strategies: Bad usage patterns - 5 days from now
  4. The useless text book algorithms - 6 days from now
  5. Find the bug: The concurrent memory buster - 7 days from now

There are posts all the way to Sep 11, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    03 Sep 2015 - The industry at large
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats