shrini1000
shrini1000

Reputation: 7236

Hibernate query cache concurrency strategy

Do Hibernate cache concurrency strategies apply to its query cache too (e.g. a cacheable query gets some scalar data, and then two queries concurrently modify that scalar data)? If not, what happens with concurrent updates (or read/updates) for queries? If yes, how to specify them for query cache?

Upvotes: 0

Views: 1036

Answers (1)

JB Nizet
JB Nizet

Reputation: 691845

The strategy is the following.

A timestamp cache keeps track of the last update timestamp for each table.

Each time a cachable query is executed and that the results are in the query cache, Hibernate checks the the timestamp of the query results is bigger (more recent) than the update timestamp of each table concerned by the query. If bigger, then the results are not stale, and the cached results are returned. If lower, then the cached results are potentially stale, and the query is executed against the database.

Upvotes: 1

Related Questions