What is second level cache in hibernate?

久未见 提交于 2019-12-18 10:09:33

问题


What is second level cache in hibernate ?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/2825436/what-is-second-level-cache-in-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!