Junior — Middle
What is the storage duration of the first-level cache in the system?
sobes.tech AI
Answer from AI
First Level Cache in Java Persistence API (JPA) exists within the scope of a single session (EntityManager). Its lifetime is limited to the lifespan of that session — meaning, the cache lives as long as the EntityManager is open.
This means that all operations with entities within a single EntityManager use the first level cache, which improves performance by avoiding repeated database queries. After the EntityManager is closed, the cache is cleared.