Erick Papadakis typed the following on 09:07 PM 1/13/2001 -0800
>but now the problem is that the client's browsers do
>not cache this. if i try images from a physical disk
>from my website in the webserver, then it works well -
>both IE and netscape remember the images!!! with
>servlets as abvoe, everytime i reload my servlet in my
>browser, my servlet calls the database. this is
>affecting the performance.

Have you implemented getLastModified() on your servlet? I would
make a simple implementation of this which returns an old time
just to test whether it will cause the browsers to use the cached
image. If so, you can write something more sophisticated.

You might have your servlet keep a hashtable of image names and 
their last modified times, so it doesn't have to check the times in
the database on each request. You could update this every time
you handle a doGet() or doPost() for the image, which will happen
when a new user - who doesn't haved the image in their cache -
accesses the image.

Better yet is to actually cache the images so you aren't making
redundant database requests even for new users. The dangers of
this are:
1) If you have many images, this could soak up a lot of memory,
2) If the images change in the database, you won't know.

The first problem can be beaten by limiting the number of images
you keep in your servlet's cache. If you get a request for an image
not in your cache and the cache is full, replace one of the images
in the cache, preferably the one which has been used least recently
(LRU - Least Recently Used). 

How you defeat the second problem depends on how often the images
will change in your database. If they don't change often, maybe you
can just stipulate that Tomcat must be restarted after images are
updated, which solves the problem without requiring extra code.

Kief


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to