Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Object caching  RSS feed

 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to keep a hash map of some object I am creating while some operation of my entity bean. I want this hashmap to be available across the whole application as long as the application runs. That is if I come back next time, I want that map be available. Now, my server is always running on a single jvm. The spec discourage me to use singleton/ static variables. So, where can I keep my hashmap? May be bind it in the Context()??
pls help.
Regards,
Sajid
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use Singleton and static variables for exactly this purpose. Be aware that you don't get one per system or one per JVM but one per class loader. This is usually ok for read only stuff that is not too big to keep in memory. If you update the cache you'll need some way to make sure every darned copy of it gets changed. If your app has any potential to go to a cluster in the future, this could be a tricky bit. My current system can clear some or all cache data from an admin screen or via an API.

Look into open source or commercial caching solutions, especially if you need to synchronize distributed caches. There are interesting ways to go wrong on this stuff, and it's probably safer to get some code that's been running a long while than to make your own.
 
James Kesari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at "object cache" opensource implementation from Apache..
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!