Difference between Nhibernate first and second level cache

Asked

Viewed 761 times

2

When searching for cache within Nhibernate, I found that there are two levels of cache that can be used, the first level and the second level. I found articles with implementations of both types and everything, but I’d like to know what the real difference is between the two. Why choose one or the other?

  • 1

    in English: http://stackoverflow.com/questions/337072/what-is-first-and-second-level-caching-in-hibernate

  • 1

    In this link, the author gives an idea of when to use the second cache: http://blog.streamlinelogic.ca/2007/03/nhibernate-cache.html

1 answer

2


  • The cache of first level is nothing more than the session (defined by the interface ISession) which stores the entities (records) loaded in memory. It is also called transaction cache. This cache prevents the same record (identified by the primary key) from being loaded twice, thus reducing memory consumption and database requests, and tracking changes made to it.

Learn more in: http://nhforge.org/doc/nh/en/index.html#Architecture-Overview

  • The cache of second level, also called query cache, is optional and can be enabled in Nhibernate settings. This cache allows you to record query’s that are performed frequently, storing their result and preventing them from running again in the database. A classic example of using this cache would be the listing of the promotional items presented on the main e-commerce page (which are the same for each user who would visit the site).

Learn more in: http://nhforge.org/doc/nh/en/index.html#performance-cache

Browser other questions tagged

You are not signed in. Login or sign up in order to post.