Home > front end >  Hibernate first level cache and spring boot
Hibernate first level cache and spring boot

Time:11-12

So my understanding around hibernate first level cache was that it is around sessions and transactions. Items remain in the cache during a transaction, but then once a transaction is closed ie request fulfilled it will clean/evict items.

But I wondered if that is wrong does the first level cache keep items after a request has been fulfilled and subsequent GET API requests go to the cache. Is there a time limit when it evicts objects from the cache.

This is in Spring boot.

CodePudding user response:

Your description of the first level cache is correct. It's per session/transaction. After the transaction is finished, the objects are left to be garbage collected.

To cache entities across sessions one needs to use the second level cache.

Using this can become a bit tricky for applications with multiple instances; depending how the application is built, one might need to use a distributed cache to have the cache in sync across instances of the application.

  • Related