I read that using the second level cache of sleep mode, it can improve application performance due to fewer database hits to retrieve data / objects.
However, how hibernate ensures that the second level cache is updated with the data in the database.
For example:
Assume that the class below is an entity and is stored in the database.
@Entity class User { Id private int id; private String str; }
Now, if we turned on the second level cache, I understand that if we open different sessions, then each session falls into the second level cache to get the value of the object.
Now, if the data in the database receives changes (for example, for a row with id = 1), say, by some independent process / manually changing the values, and we try to access this value, as hibernate detects that the cache has the last value (for id = 1).
In general, how hibernate ensures that data in a second-level cache matches db values.
Thank you for your help.
source share