This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Caching in an EJB container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Caching in an EJB container" Watch "Caching in an EJB container" New topic

Caching in an EJB container

Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I have a problem in figuring out how to do some caching of reference data.
We are developing a clustered app (using WebLogic 6.1 SP5) which requires data to be cached on the server. The data is produced by five DAO classes which retrieve data from the DB and return the reference data as an array. The idea is to then run the SQL queries daily and, if there is a discrepancy with the cache, to overwrite any or all of the five cached arrays with the new data. Oh, we are also going to store a timestamp for each cached array.
A stateless session bean is going to be the user (reader) of the cached data.
Now, storing the arrays in the DB is possible but ruled out by our tech lead who does not wish to make any changes to the DB at this stage of the project. We've agreed that memory caching would be fine, but how can I do it in a way that does not violate the EJB 2.0 spec? I can't use in my bean non-final static variables, and I can't serialize to file even if I wanted to.
I'm not sure whether it's a good idea to cache in a singleton class, as I don't know how you can guarantee that you really do have a singleton in a container.
Any ideas gratefully received ...

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Kyle's recent article in our newsletter might be of interest to you.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Caching in an EJB container
It's not a secret anymore!