user3828255
user3828255

Reputation: 11

How will cache came to know that database is updated?

I am new to the Hibernate.In hibernate,if we send same request for multiple times the data will be available in cache.Is it true?If it is true,after giving the same request for 2 times i have changed the data base column data using sql prompt.again i have send same request then what it will do?Is it checks in cache? or goto database?

Upvotes: 1

Views: 672

Answers (1)

The quick answer is cache is not aware of updates made from other database sessions.

It is your responsibility as programmer to use cache correctly.

First of all hibernate has several types of caches. Session (or first level) cache lives for duration of the hibernate session. This cache always works and some session methods use it and some bypass it. See details for 4.x or for 3.x.

Second level cache is turned off by default and if it is turned on cache mode of the session determines whether cache is consulted first or call to database is performed for particular request.

Unlike first level cache the second level cache is plugable and cache providers usually allow to configure how long particular objects are stored in cache before eviction and refresh. Here is example for ehcache.

Upvotes: 1

Related Questions