winter
winter

Reputation: 2917

Hibernate in memory data + database

I have an application which already written in Hibernate and is mapped to hiberante database annotations (and in the background I am using Postgres as DB). I was wondering if there is a way to keep the database as is, but to add another level of "database" which holds everything In-Memory in java object?

What I mean is, 1) keep Postgres update when there is update/delete/create and only return after it is really commited.

2) when some DB Read queries executed, I want to be able to return the answer using my java object And avoid calling the database for those Read operations

Upvotes: 0

Views: 429

Answers (1)

Matthew Fontana
Matthew Fontana

Reputation: 3870

Hibernate has an awesome feature built in called a second level cache. This will allow you to "plugin" a caching system like ehcache to offload a lot of the database read load. Ehcache can either be used standalone or in a distributed manor. Ehcache on its own is a very powerful tool that you can also leverage in front of webservice calls and other lookups as well. I will post a few decent reading links for you.

http://howtodoinjava.com/hibernate/hibernate-ehcache-configuration-tutorial/

http://www.mkyong.com/ehcache/ehcache-hello-world-example/

You can also consider using spring with ehcache for a more declarative caching style if you want to use it standalone

http://www.mkyong.com/spring/spring-caching-and-ehcache-example/

Upvotes: 1

Related Questions