Caching in Hibernate

Hibernate caching improves the performance of the application by pooling the object in the cache.

Caching in Hibernate

Caching in Hibernate

Hibernate caching improves the performance of the application by pooling the object in the cache. It is useful when we have to fetch the same data multiple times.

There are mainly two types of caching:

  • First Level Cache, and
  • Second Level Cache

First Level Cache

The session object holds the first level cache data. It is enabled by default. The first level cache data will not be available to the entire application. An application can use many session objects.

Second Level Cache

SessionFactory object holds the second level cache data. The data stored in the second level cache will be available to the entire application. But we need to enable it explicitly.

  • EH (Easy Hibernate) Cache
  • Swarm Cache
  • OS Cache
  • JBoss Cache