Khush
Khush

Reputation: 863

Hibernate Secondary Level Cache

Scenario: Project consists of reference data which is updated once a week. Hence constantly querying this reference data for every transaction from the database is not efficient. Hence the motivation to cache this data.

Question: If secondary level caching and query caching in Hibernate is activated and the cache element in the hibernate configuration is set to read-only, how will hibernate know when to update the cache if a change is made to the database via another program. Is this automatically handled by Hibernate or do we have to clear the cache using some trigger? If this is handled by Hibernate could someone shed light on how this is handled?

The JBoss documentation was not very clear about the management of the cache.

I am currently using Hibernate 3.6 with Spring 3.1 and do not wish to upgrade to Hibernate 4 if its not necessary.

Upvotes: 1

Views: 110

Answers (1)

stringy05
stringy05

Reputation: 7067

It wont.

The second level cache expects all access to the data to happen via the ORM framework so if you have another actor in the db your cache will become stale.

You can clear the cache though - see this code snippet

So you could expose a service that allows the 3rd party to clear the cache on your app when the database gets updated.

Upvotes: 1

Related Questions