wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Caching Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Caching Data" Watch "Caching Data" New topic
Author

Caching Data

D. Rose
Ranch Hand

Joined: Apr 25, 2003
Posts: 215
Hi,
Is it possible to cache data in server to boost performance(HTTPsession?Application scope?)?
Or shall we only depend on DB caching?
Can anybody give good links on the topic?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1164
D. Rose,

Entity beans cache objects in memory to boost performance.

http://java.sun.com/developer/onlineTraining/EJBIntro/EJBIntro.html explains the concept very well:

Containers will manage many beans simultaneously in the same fashion that the Java WebServer manages many servlets. To reduce memory consumption and processing, containers pool resources and manage the lifecycles of all the beans very carefully. When a bean is not being used, a container will place it in a pool to be reused by another client, or possibly evict it from memory and only bring it back when its needed. Because client applications don't have direct access to the beans--the container lies between the client and bean--the client application is completely unaware of the containers resource management activities. A bean that is not in use, for example, might be evicted from memory on the server, while its remote reference on the client remains intact. When the client invokes a method on the remote reference, the container simply re-incarnates the bean to service the request. The client application is unaware of the entire process.


Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Louise Elliott
Greenhorn

Joined: Aug 02, 2004
Posts: 11
For performance some caching might come in handy. You could use HTTP session or entity EJBs as suggested. Another option would be a stateful session bean. I suggest that you have a look at the java petstore example application if you haven't done so already.
D. Rose
Ranch Hand

Joined: Apr 25, 2003
Posts: 215
Thanks for your replies.
In blueprints, catalog is in Shopping cart session bean. Catalog is directly read via DAO (no entity bean)for browsing purposes (Fast lane reader).
Can Catalog be stored in some read only cache ( given that product information does not change as often) for better performance?
[ August 25, 2004: Message edited by: D. Rose ]
Louise Elliott
Greenhorn

Joined: Aug 02, 2004
Posts: 11
Sure you could cache the catalog data. But you need to consider the amount of memory which would be needed to cache the whole catalog. Do you have that much to play with? Some approaches might be to cache only certain data - or cache the results of queries for a certain length of time.

How would you index the cached data? You don't want to reinvent the database functionality... You could cache the data for a query and if the same query comes up again you could give the same results (assuming tha data doesn't change that often). Ask yourself whether the same query is likely to happen many times and if not what is the point of caching?
H. Hafer
Ranch Hand

Joined: Aug 23, 2004
Posts: 108
Originally posted by Louise Elliott:
You could cache the data for a query and if the same query comes up again you could give the same results (assuming tha data doesn't change that often). Ask yourself whether the same query is likely to happen many times and if not what is the point of caching?


Taking this as a quite good explanation why not to cache data at all for the purposes given in the requirements.

As a side note, this doesn't obsoletes the utilisation of Fast Lane Readers, right?

Thanks,
Harbo
Frank Silbermann
Ranch Hand

Joined: Jun 06, 2002
Posts: 1379
Wouldn't the caching of static data reduce the number of trips to the database? Caching it closer to the client reduces the need for expensive distributed operations.
Ramon Gill
Ranch Hand

Joined: May 15, 2003
Posts: 344
Frank, you're right. It's a question of weighing up whats important - memory verses speed.
Ray
Serge Adzinets
Ranch Hand

Joined: Nov 26, 2002
Posts: 166
By the way, entity beans are cached only if the app.server has an exclusive access to the database. If you have a cluster or a legacy application that changes the data, this just does not work.

If you have a cluster and want to cache data that is not user-specific, you may want to use some distributed cache solution.


Best Regards,<br />Serge
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Caching Data
 
Similar Threads
maintaining history in mobile
Servlet grabbing previous data/caching
Hibernate Caching
paint method problem
CVS Doesn't recognize change