Caching is one of the important features implemented by an application for better performance. In an ORM perspective, data retrieved from a database is cached in memory or to disk so that there is no need to make a call to the database for every request. A cache is a local copy of the information from the database that may be used to avoid a database call whenever:
The application performs a lookup by identifier.
The persistence layer resolves an association or collection lazily.
In Figure 12-1, when an application queries for data, the first time Hibernate fetches it from the database; from then on, it fetches data from the cache if the same data is requested.
Figure 12-1. How Hibernate caches
Hibernate provides a ...