Hibernate / EclipseLink Interview questions
What is the EclipseLink shared cache (L2 cache)?
The shared cache, often called the second-level (L2) cache, stores entity instances at the EntityManagerFactory level, shared across every EntityManager created from that factory. This is distinct from the first-level cache (the persistence context inside a single EntityManager), which only lives for the duration of that EntityManager.
When an entity is read again, whether from a different EntityManager or a later request, EclipseLink can return it straight from the shared cache instead of issuing a new SQL query, which significantly cuts down on database round-trips for data that doesn't change often.
Cache behavior per entity type is configurable through @Cache, controlling things like cache size, expiry, and whether the entity is cached at all; entities that change frequently or represent highly sensitive per-user data are often excluded from the shared cache or given a short expiry to avoid serving stale or inappropriate data.
More Related questions...