Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Hibernate Caching

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are using some lookup tables. We decided to use Hiberante caching for reducing database hit. Whether First-level or second-level caching(EHCache) suits our scenario ? Normally caching suits maximim of how many records(without affecting performance) ?
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any update ???
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to determine which type of caching strategy is best for you. We do not know what your system is or what it is doing.

For your second question. There doesn't seem to be any limits set on the number of rows that you can cache.

Link to the Hibernate documentation on Caching:

http://www.hibernate.org/hib_docs/reference/en/html/performance.html

Best of Luck.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Nathan, For less number of records(not huge volumes of data), which caching(first-level caching or second-level caching) suits ?
 
Nathan Hook
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kri,

The difference is when and where the data gets cached.

http://www.devx.com/dbzone/Article/29685/

If you look at the above website and under the Hibernate Caching heading there is a nice explanation of First-level vs. Second-level caching.

First-level attaches the cached data to the session.
Second-level attaches the cached data to the session factory.

So, personally I would recommend using Second-level caching (if you're using the session per request hibernate design pattern). However, there is a price to pay with Second-level caching. The data that is cached will never be updated from the database.

Now, there are a few ways around having stale data in your cache.

1.) Restart your application when there is a change.
2.) Don't use hibernate caching and store the data needed in a static class or singlton and have a way to query the database to update that cached data. (I do not know if there is a way to request hibernate to update its Second-level cache at this time. My guess is requesting a new session factory would do the job, but it does take a while to generate a new session factory.)
3.) Don't cache the data. (Are the database hits causing a perceived slow down on your application? Have you run your code through a profiler to see if the database calls are slowing your application down? etc...) It is not always necessary to cache data from lookup tables. I'm sure some people will disagree, but until there is evidence from a profiler for any type of "speed enhancement" I shy away from programming them myself.

Hope this helps.
[ August 30, 2007: Message edited by: Nathan Hook ]
 
Why is the word "abbreviation" so long? And this ad is so short?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic