Difference between first and second level NHibernate cache

2

When searching for cache within NHibernate, I came across that there are two cache levels 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?

    
asked by anonymous 02.11.2014 / 15:40

1 answer

2
  • The first level cache is nothing more than the session (defined by the ISession interface) that stores the entities (registers) loaded into memory. Also called transaction cache . This cache prevents the same registry (identified by the primary key) from being loaded twice, thereby reducing memory consumption and requests to the database, as well as tracing the changes made to it.

Learn more at: link

  • The second level cache , also called a query's cache , is optional and can be enabled in NHibernate settings. This cache allows you to log queries that are frequently performed, storing their result and preventing them from being run back into the database. A classic example of using this cache would be the listing of promotion items displayed on the main e-commerce page (which are the same for each user who would visit the site).

Learn more at: link

    
03.11.2014 / 00:55