• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Global Application Data (Best Practices Question)  RSS feed

Caden Whitaker
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a website translated in 16 languages

1: The website will get new translations and changes but in a very infrequent basis (say once every 6 weeks)

2: There is no need to hit repeatedly hit the database for the hundreds of thousands of users hitting this website just to get the website text.

3: It makes more sense to simply store all of this text in application memory (on the webserver) and pull it from there and have this application memory periodically check for changes (once every 24 hours)

4: Rather then have the change set to set time (24 hours) I'd rather hibernate routinely check the "last_modified" date of the text it has cached, if it has changed then update

So here's the table in question
application_text_id (key)
language_id (foriegn key to language table)
last_modified (datetime)

so I would say "get me text id 5 for language 23" and instead of going to the database it would simply return that object from memory.

Now, I can write this up myself. But I'm wondering if you all had any recommendations for best practice in a situation like this.

Any help would be appreciated

xsunil kumar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure, whether this is right way to solve this problem but one way i am looking is to place this object in application level scope.

if(getServletContext().getAttribute("VALUE_FROM_DATABASE") ==null) {

// get the value from database and set it to scope
getServletContext().setAttribute("VALUE_FROM_DATABASE", <VALUE FROM DATABASE>); // set the value to application level scope.

} else {

In this way , this value will be available for diffenrent sessions also. so this will reduce your database hits.

Now if you want to change this value after some days like 6 days, then just ovverride this attribute with new value. You can use below logic to find how old this value has been set in scope .

create one more appication level variable like

getServletContext().setAttribute("SAVED_DATE", <CURRENT DATE>);

So, whenever you fetch value from appliction scope, then fetch saved_date also. and compare it saved date is 6 days old than today's date. If yes, then do database operations and set both values again.

Hope this will help you,

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!