Understanding Hibernate Caching –
Hibernate caching is used to optimize application performance, it minimizes the DB connection cost thus reduces data fetch time. First time it will fetch data from DB a
nd load objects then these objects will be stored in cache(like in files), on request from next time onwards it will pick from cache. So it is very faster.
Hibernate supports two level of caching –
- First Level Cache
- Second Level Cache
Hibernate uses first-level cache by default and you have nothing to do to use first-level cache. Second-level cache is optional.
First Level Cache:
Session object holds the first level cache data. It is enabled by default. The first level cache data will not be available to entire application. Objects will be cached within the same session. If you close the session, all the objects being cached are lost and either persisted or updated in the database.
Second Level Cache:
SessionFactory object holds the second level cache data. The data stored in the second level cache will be available to entire application. But we need to enable it explicitly.
you can use any third-party cache with Hibernate. An org.hibernate.cache.CacheProvider interface is provided, which must be implemented to provide Hibernate with a handle to the cache implementation.
Second Level Cache implementations are provided by different vendors such as:
Latest posts by Gopal Das (see all)
- Salesforce Certified Platform Developer I – Winter ’18 Release Exam - November 23, 2017
- Salesforce Certified Platform App Builder – Winter ’18 Release Exam - November 22, 2017
- Salesforce Certified Administrator – Winter’ 18 Release Exam - November 21, 2017