Friday, March 23, 2007

Why do they call it C#(sharp) and not C3?

First let us take a look at the different versions of C. Let us assume the following C =1. After C we had C++. As you can recall the ++ operator is used to increment a value by 1. Thus C++ becomes C2. Naturally one would then assume the next version of C would be C++++. So how does c++++ become c#. If you rearrange the four plus(+) symbols you can create a hash(#) symbol. Another reason the hash symbol may have been used is that the hash symbol can be found on the number 3 on the keyboard. If this is accurate please let me know.

Based on my assumptions the next version of C could be one of the following:

  1. C4
  2. C++++++
  3. C#+1
  4. C$ (Can you see it... The plus symbols are rearranged to make a dollar sign. )

NHibernate First and Second Level Cache

One of the more powerful features of NHibernate is the ability to cache object data in memory. This feature provides software developers with the means to create faster more responsive applications. NHibernate provides software developers with two levels of cache the first level cache and the second level cache.

First Level Cache


By default NHibernate uses a first Level Cache. The first level cache is located on the session level. Requests for the same object will query the database only once. In a typical NHibernate application one would do the following:


  1. Obtain a session object form the session factory.
  2. Start a transaction. ISession.BeginTransaction()
  3. Perform a CRUD(create, retrieve, update, delete) operation using the session object.
  4. Close the session object. ISession.Close().
Inorder to use the cache we must request the same object in step 3 before the session is closed. The following will demonstrate the use of the first level cache.


  1. Obtain a session object form the session factory.
  2. Start a transaction. ISession.BeginTransaction()
  3. Retrieve object with ID=1. The object is retrieved from the database.
  4. Retrieve object with ID=1. The object is retrieved from the cache.
  5. Close the session object. ISession.Close()
  6. Obtain a session object from the session factory.
  7. Start a transaction. ISession.BeginTransaction()
  8. Retrieve object with ID=1. The object is retrieved from the database
  9. Close the session object. ISession.Close()
Second Level Cache

The second level cache is optional. The second level cache is located at the Session Factory level. The second level cache can cache object data from different sessions. This means that all session objects can access the same cached data. The intended purpose of the second level cache is to make a good application better. The second level cache should not be used as solution to increase the speed of an under preforming application. NHibernate supports the use of different cache providers. According too NHibernate 1.2 documentation three cache providers are provided hashtable cache, asp.net cache and prevalence cache.

For more information please visit the Hiberbate website.