At 09:15 AM 4/17/2001 -0400, Alex Colic wrote:
>Lets say you have a web app that runs over a number of web pages in a wizard
>fashion. On each one of these pages you need to present the user with a
>select box holding lists. e.g. locations, cities, etc. This data is read
>from a database and rarely changes.
>
>How would you cache these lists so that as each user access this site they
>do not need to have this info downloaded again?

you could have a singleton data storage class that dumps the
country list into a hashmap.  if the country cache existed, the
class would return the list from there - otherwise it would
go to the database and populate the cache... (1x)

the singleton class is only instantiated once for the app,
or potentially once per cluster node.  use getInstance()
to return the sole instantiation of the class...

ie.
public class MyClass() {

   private static MyClass singleton = new MyClass();
   private HashMap countries = null;

   //constructor
   private MyClass() {
   }

   public getInstance() {
     return singleton;
   }
}

along the lines of that - i think...  caveat -
may have some errors above, i'm writing it off the cuff.

>I was thinking in the init() of my ActionServlet to access the database and
>get these lists then place them in the session with Application scope. I
>think this would allow each user to access the data without reaccessing the
>database.

i think there's some additional overhead in putting this in App scope.
Also potentially costs in clustering depending on servlet runner. (weblogic?)

i'm not super familiar with how App scope is managed, but the issue
seems to be more of a db abstraction layer sort of issue rather than
a presentation one.  i'd deal with the data in the layer where it
generally is handled, rather than pushing it all the way up the app
to the presentation layer (Struts).

just my $0.02 though,
chris

Reply via email to