开发者

What is second level cache in hibernate?

开发者 https://www.devze.com 2022-12-29 23:07 出处:网络
What is开发者_如何学Go second level cache in hibernate ?Hibernate comes with three different caches: first level, second level and query cache.

What is开发者_如何学Go second level cache in hibernate ?


Hibernate comes with three different caches: first level, second level and query cache.

The first level cache is the Hibernate Session and is used to track the state of entities during the current Session (or unit of work). This is a transaction-level cache.

The second level cache shares entity state across various Session. This is a SessionFactory-level cache.

The query cache is used to cache queries (and their parameters) and their results.

Recommended readings

  • The Second Level Cache in the documentation
  • Hibernate: Truly Understanding the Second-Level and Query Caches
  • Understanding Caching in Hibernate – Part One : The Session Cache
  • Hibernate Caches


First level cache is enabled by default and works in session scope.Second level cache is apart from first level cache which is available to be used globally in session factory scope. Therefore second level cache is created in session factory scope and is available to be used in all sessions which are created using that particular session factory. It also means that once session factory is closed, all cache associated with it die and cache manager also closed down. Whenever hibernate session try to load an entity, the very first place it look for cached copy of entity in first level cache and if there is no cached entity in first level cache, then second level cache is looked up for cached entity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号