Caching is a way to improve the performance of an application. It uses buffer memory to stores recently used data from database to minimize the database hits.
Cache is useful when same data have to be fetched several times.
Types of cache in hibernate:
- First level cache
- Second level cache
First level cache in hibernate:
In hibernate, first level cache is enabled by default. First level cache is maintained by session objects. Data available in first level cache will be available in that particular session only.
Second level cache in hibernate:
In hibernate, second level cache is not enabled by default. We need to enable it explicitly. Second level cache is maintained by session factory objects. Data available in second level cache is available in all sessions in the application.