Friday, March 23, 2007

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.

8 comments:

Sarah on Nhibernate Cache said...

Thanks for mentioning the various options that you have for second level Nhibernate Cache. Just wanted to point out that NCache is a great second level caching option for NHibernate users. Check it out.

Cheers!

Anonymous said...

CHINA CHOW NUDE
[url=http://my.curse.com/members/LORINDA3.aspx]CHINA CHOW NUDE[/url]
CHINA CHOW NUDE
[url= http://my.curse.com/members/LORINDA3.aspx ] CHINA CHOW NUDE [/url]
MICHELLE HUNZIKER NUDE
[url=http://my.curse.com/members/LORINDA3.aspx]MICHELLE HUNZIKER NUDE[/url]
MICHELLE HUNZIKER NUDE
[url= http://my.curse.com/members/LORINDA3.aspx ] MICHELLE HUNZIKER NUDE [/url]
KATHLEEN ROBERTSON NUDE
[url=http://my.curse.com/members/LORNA3.aspx]KATHLEEN ROBERTSON NUDE[/url]
KATHLEEN ROBERTSON NUDE
[url= http://my.curse.com/members/LORNA3.aspx ] KATHLEEN ROBERTSON NUDE [/url]
LACEY CHABERT NUDE
[url=http://my.curse.com/members/LORRETTA3.aspx]LACEY CHABERT NUDE[/url]
LACEY CHABERT NUDE
[url= http://my.curse.com/members/LORRETTA3.aspx ] LACEY CHABERT NUDE [/url]
JOSIE MARAN NUDE
[url=http://my.curse.com/members/LORRIANE2.aspx]JOSIE MARAN NUDE[/url]
JOSIE MARAN NUDE
[url= http://my.curse.com/members/LORRIANE2.aspx ] JOSIE MARAN NUDE [/url]

Anonymous said...

LYDIA HEARST NUDE
[url=http://my.curse.com/members/LORRIN1.aspx]LYDIA HEARST NUDE[/url]
LYDIA HEARST NUDE
[url= http://my.curse.com/members/LORRIN1.aspx ] LYDIA HEARST NUDE [/url]
ALANIS MORISSETTE NUDE
[url=http://my.curse.com/members/LOUANN1.aspx]ALANIS MORISSETTE NUDE[/url]
ALANIS MORISSETTE NUDE
[url= http://my.curse.com/members/LOUANN1.aspx ] ALANIS MORISSETTE NUDE [/url]
NEVE CAMPBELL NUDE
[url=http://my.curse.com/members/LOUELLA2.aspx]NEVE CAMPBELL NUDE[/url]
NEVE CAMPBELL NUDE
[url= http://my.curse.com/members/LOUELLA2.aspx ] NEVE CAMPBELL NUDE [/url]
PATSY KENSIT NUDE
[url=http://my.curse.com/members/LOUIE7.aspx]PATSY KENSIT NUDE[/url]
PATSY KENSIT NUDE
[url= http://my.curse.com/members/LOUIE7.aspx ] PATSY KENSIT NUDE [/url]
ROSE BYRNE NUDE
[url=http://my.curse.com/members/LOUISE3.aspx]ROSE BYRNE NUDE[/url]
ROSE BYRNE NUDE
[url= http://my.curse.com/members/LOUISE3.aspx ] ROSE BYRNE NUDE [/url]

Anonymous said...

AMBER TAMBLYN NUDE
[url=http://my.curse.com/members/LIBBIE5.aspx]AMBER TAMBLYN NUDE[/url]
AMBER TAMBLYN NUDE
[url= http://my.curse.com/members/LIBBIE5.aspx ] AMBER TAMBLYN NUDE [/url]
AGYNESS DEYN NUDE
[url=http://my.curse.com/members/LIBERTY4.aspx]AGYNESS DEYN NUDE[/url]
AGYNESS DEYN NUDE
[url= http://my.curse.com/members/LIBERTY4.aspx ] AGYNESS DEYN NUDE [/url]
KRISTIN KREUK NUDE
[url=http://my.curse.com/members/LIBRADA7.aspx]KRISTIN KREUK NUDE[/url]
KRISTIN KREUK NUDE
[url= http://my.curse.com/members/LIBRADA7.aspx ] KRISTIN KREUK NUDE [/url]
AMY POEHLER NUDE
[url=http://my.curse.com/members/LIESELOTTE3.aspx]AMY POEHLER NUDE[/url]
AMY POEHLER NUDE
[url= http://my.curse.com/members/LIESELOTTE3.aspx ] AMY POEHLER NUDE [/url]
LEELEE SOBIESKI NUDE
[url=http://my.curse.com/members/LILLIA8.aspx]LEELEE SOBIESKI NUDE[/url]
LEELEE SOBIESKI NUDE
[url= http://my.curse.com/members/LILLIA8.aspx ] LEELEE SOBIESKI NUDE [/url]

Anonymous said...

JERI RYAN NUDE
[url=http://my.curse.com/members/LILLIAN5.aspx]JERI RYAN NUDE[/url]
JERI RYAN NUDE
[url= http://my.curse.com/members/LILLIAN5.aspx ] JERI RYAN NUDE [/url]
ELSA PATAKY NUDE
[url=http://my.curse.com/members/LILLIANA4.aspx]ELSA PATAKY NUDE[/url]
ELSA PATAKY NUDE
[url= http://my.curse.com/members/LILLIANA4.aspx ] ELSA PATAKY NUDE [/url]
SHAUNA SAND NUDE
[url=http://my.curse.com/members/LILLIE6.aspx]SHAUNA SAND NUDE[/url]
SHAUNA SAND NUDE
[url= http://my.curse.com/members/LILLIE6.aspx ] SHAUNA SAND NUDE [/url]
BILLIE PIPER NUDE
[url=http://my.curse.com/members/LINETTE4.aspx]BILLIE PIPER NUDE[/url]
BILLIE PIPER NUDE
[url= http://my.curse.com/members/LINETTE4.aspx ] BILLIE PIPER NUDE [/url]
KIM CATTRALL NUDE
[url=http://my.curse.com/members/LINNEA6.aspx]KIM CATTRALL NUDE[/url]
KIM CATTRALL NUDE
[url= http://my.curse.com/members/LINNEA6.aspx ] KIM CATTRALL NUDE [/url]

Anonymous said...

NIKKI COX NUDE
[url=http://my.curse.com/members/MADELENE2.aspx]NIKKI COX NUDE[/url]
NIKKI COX NUDE
[url= http://my.curse.com/members/MADELENE2.aspx ] NIKKI COX NUDE [/url]
ALICIA SILVERSTONE NUDE
[url=http://my.curse.com/members/MADELINE5.aspx]ALICIA SILVERSTONE NUDE[/url]
ALICIA SILVERSTONE NUDE
[url= http://my.curse.com/members/MADELINE5.aspx ] ALICIA SILVERSTONE NUDE [/url]
JENNA FISCHER NUDE
[url=http://my.curse.com/members/MADELYN7.aspx]JENNA FISCHER NUDE[/url]
JENNA FISCHER NUDE
[url= http://my.curse.com/members/MADELYN7.aspx ] JENNA FISCHER NUDE [/url]
ALESSANDRA AMBROSIO NUDE
[url=http://my.curse.com/members/MADISON3.aspx]ALESSANDRA AMBROSIO NUDE[/url]
ALESSANDRA AMBROSIO NUDE
[url= http://my.curse.com/members/MADISON3.aspx ] ALESSANDRA AMBROSIO NUDE [/url]
UMA THURMAN NUDE
[url=http://my.curse.com/members/MADONNA4.aspx]UMA THURMAN NUDE[/url]
UMA THURMAN NUDE
[url= http://my.curse.com/members/MADONNA4.aspx ] UMA THURMAN NUDE [/url]

Anonymous said...

how well does accutane work

http://accutane.socialgo.com

Anonymous said...

Alachisoft is a California Corporation under the legal name Diyatech Corp. Alachisoft provides companies powerful yet simple way to improve the performance of their .NET applications and also to cut down their development cycle with improved code quality. Products are NCache (Boost .NET App Performance & Scalability), StorageEdge (Optimized Storage for SharePoint) and TierDeveloper (Rapidly Develop .NET Applications)
Link: “http://fr.alachisoft.com/”