You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lyallex <ly...@gmail.com> on 2009/06/10 15:41:54 UTC

Loading dynamically created content: An old chestnut but still a problem.

apache-tomcat-6.0.16
jdk1.6.0_03

Dev box : Windows
Deployment box: Linux

Hi

I've read some other posts that seem to be asking similar questions
but I can't find the answer so far.
maybe someone here would be kind enough to give me a hint

I have a retail application that stores the product images in a database.
Each product can have many images and products are being uploaded all the time.

Fetching images from the database every time results in a clunky page
load so I want to cache the images to disk
the first time an item is accessed my cache manager checks the disk
cache to see if images for that item are available.
If not it loads them onto the disk.
this happens in the servlet that serves the item details up so the
images are in the disk cache before the request is forwarded to the
view (jsp)
In the jsp I access the images from the disk cache.

The problem is, the first time I access the item details the images
are written to the cache which resides directly under the
context root but they are not loaded in the view.
If I restart tomcat the images disply fine so I know all the caching
is working correctly.

I can't restart tomcat everytime I upload a new product so how can I
force tomcat to recognise the new images 'on the fly' so as to speak?
The application is running as the ROOT application on the server and
is the only application being served.

An example image might be
../apache-tomcat-6.0.16/webapps/ROOT/imagecache/8000030_main.jpg
(example)

I'm quite happy that the imagecache is deleted everytime I redeploy
the application because the application is starting to stabilise and
once I have this last problem ironed out
I will only be doing irregular maintenance. The faster loading of
images is more than enough compensation.

I can't use symbolic links to place the imagecache outside the
application space because I develop on Windows and deploy to Linux
(historical, nothing I can do about it)

Any ideas much appreciated.


Many thanks
lyallex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by André Warnier <aw...@ice-sa.com>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Lyallex,
> 
> On 6/10/2009 9:41 AM, Lyallex wrote:
>> Fetching images from the database every time results in a clunky page
>> load so I want to cache the images to disk
>> the first time an item is accessed my cache manager checks the disk
>> cache to see if images for that item are available.
>> If not it loads them onto the disk.
> 
> I'm interested: what db are you using, what is your network topology,
> and what kind of performance increase are you observing?
> 
> Also, what code are you using to serve the bytes of the locally-cached
> files? DefaultServlet?
> 
>> I can't use symbolic links to place the imagecache outside the
>> application space because I develop on Windows and deploy to Linux
>> (historical, nothing I can do about it)
> 
> This shouldn't matter: you should be able to write files anywhere you
> please. You don't have to be restricted to the deployment directory.
> What about writing to C:\imagecache or ~/imagecache?
> 
And what about storing your images entirely outside of the db, as simple 
files, and only keeping a link in the db ?
That would allow *any* cache mechanism to work in a much simpler fashion 
(including the browser's), and would probably immensely unload your db 
software, which right now has to handle big "blob" data in each record.
It would also allow asynchronous mechanisms (like sendfile) to handle 
the sending of these images much more efficiently.
Not even considering the time you'd gain in db maintenance operations.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lyallex,

On 6/10/2009 9:41 AM, Lyallex wrote:
> Fetching images from the database every time results in a clunky page
> load so I want to cache the images to disk
> the first time an item is accessed my cache manager checks the disk
> cache to see if images for that item are available.
> If not it loads them onto the disk.

I'm interested: what db are you using, what is your network topology,
and what kind of performance increase are you observing?

Also, what code are you using to serve the bytes of the locally-cached
files? DefaultServlet?

> I can't use symbolic links to place the imagecache outside the
> application space because I develop on Windows and deploy to Linux
> (historical, nothing I can do about it)

This shouldn't matter: you should be able to write files anywhere you
please. You don't have to be restricted to the deployment directory.
What about writing to C:\imagecache or ~/imagecache?

Also, on Windows, you might check out mklink.exe

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkowJeYACgkQ9CaO5/Lv0PASNwCfXxHdleZYBlVDr8ClI+seB/14
+qYAoKundWQ0c+HeYYD1J0xEVSGwhMX0
=9PcM
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Lyallex <ly...@gmail.com>.
Christopher

> Multiple posts to this list seem to contradict Hassan's assertion that
> this should work: the DefaultServlet appears to ignore files that are
> created post deployment (or at least, post directory-read).

This is exactly what is happening, the DefautServlet Ignores any file
that appears in the application space after the server is started
Others who have replied to my original post appear to have no problem
serving up images that have been uploaded after server startup ...

I appear to have multiple issues here. Rather that 'hijack' my own
thread, I'll start a new one for each issue then return here when I
know exactly what the problem is. I hope this doesn't upset too many
people.

Rgds
lyallex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lyallex,

On 6/10/2009 6:27 PM, Christopher Schultz wrote:
> I would recommend serving the bytes using your own servlet rather than
> the DefaultServlet. That way, you free yourself from these apparent
> directory-caching issues, plus you can (more) easily move your image
> cache out of your deployment directory (if you care).

Scratch that... after reading André's response, I realized that you
might not be able to (easily) use sendFile if you write the code
yourself. Use of sendFile (for connectors that support it) for static
content is strongly recommended for increased performance.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkowNBQACgkQ9CaO5/Lv0PDzZgCgo1oF8LB4X79tXpBmCSwcu3b7
IGcAnAvktD70TcaCeLzZDax1+YCEVnxQ
=/nNl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lyallex,

On 6/10/2009 1:10 PM, Lyallex wrote:
> <img src="ImageProxy?<%=WebConstants.IMAGE_ID%>=<%=p.calculateImageId()%>...
> etc '/>
> 
> This gets the image from the database and displays it in the page.
> 
> This is clunky and slow and the image is not cached by the browser

You might want to set some caching headers, etc. if you want the browser
to cache the image. You'll have the same problem with locally-cached
files if you don't do this (DefaultServlet, which it sounds like you're
using, probably sets these headers appropriately).

> Anyway, I'm currently looking at the serveResource() method in the
> DefaultServlet...

Multiple posts to this list seem to contradict Hassan's assertion that
this should work: the DefaultServlet appears to ignore files that are
created post deployment (or at least, post directory-read). This is
either due to the servlet itself or the (IIRC) JNDI context used by the
DefaultServlet to read the files.

I would recommend serving the bytes using your own servlet rather than
the DefaultServlet. That way, you free yourself from these apparent
directory-caching issues, plus you can (more) easily move your image
cache out of your deployment directory (if you care).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkowMzYACgkQ9CaO5/Lv0PBFhACdFH4WalukRH68QqDgwStOM5sm
4hMAnApwfMGuF2xUuXGOw2Z/7o9WFy2X
=WUup
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Hassan Schroeder <ha...@gmail.com>.
On Wed, Jun 10, 2009 at 10:10 AM, Lyallex<ly...@gmail.com> wrote:

> When I upload a new product I store the image data and the text in the
> database. I did this to try and separate the data from the application
>  with the intention of eventually having the data reside on a separate
> device optimised for serving data ... well that was my original
> thinking anyway.

which, BTW, still doesn't necessarily imply storing images in the DB,
but whatever floats your boat. :-)

> it appears the DefaultServlet will not load resources that have been
> written to disk after the server has been started.

? Works fine for me -- I frequently load new product images to sites
on my server, and no restart is required.

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Tim Funk <fu...@apache.org>.
Odd

Personally - I would do the following:

Make all calls to the servlet and the servlet does this:

1) Sanity check the incoming path
2) Check for the existence of the image (using 
ServletContext.getResource(path)
3) If not exists - load the image from the db and store to disk
4) forward to image via 
request.getRequestDispatcher(path).forward(request, response)

The above assumes the image cache directory is part of the webapp and 
visible to ServletContext.getResource

If the image cache directory lives outside the webapp - then I amazed 
that the default servlet was ever working. In which case - you can use a 
symlink.

If you are stuck on windows or all the above still doesn't work - then 
you can still do this:

0) In apache - you can map the image cache dir to some location - or 
have tomcat do that too in its own webapp
1) Sanity check the incoming path
2) Check for the existence of the image using a filesystem call
3) If not exists - load the image from the db and store to disk
4) redirect to the static image path


-Tim


Lyallex wrote:
> Hi
>
> I'll try to explain in as few words as possible.
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Lyallex <ly...@gmail.com>.
2009/6/11 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: Loading dynamically created content: An old chestnut but
>> stilla problem.
>>
>> I suspect that Hassan and Chuck are nto using anti-resource-locking
>> while Lyallex is.
>
> Correct; as stated, both Hassan and I are using stock Tomcat 6.0.20 downloads.
>
> If the external webapp approach I suggested is used, the antiResourceLocking attribute should be set to false for that <Context>.
>
>  - Chuck
>
>

I have this working now. I removed the locking attributes from the
context as explained in the other thread.

Thanks to all those who took the time to reply, it's much appreciated.

lyallex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Loading dynamically created content: An old chestnut but still a problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: Loading dynamically created content: An old chestnut but
> stilla problem.
> 
> I suspect that Hassan and Chuck are nto using anti-resource-locking
> while Lyallex is.

Correct; as stated, both Hassan and I are using stock Tomcat 6.0.20 downloads.

If the external webapp approach I suggested is used, the antiResourceLocking attribute should be set to false for that <Context>.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mark,

On 6/11/2009 9:36 AM, Mark Thomas wrote:
> This all all a expected side-effect of using the anti resource locking
> features.

Oh, good: some /real/ information as to the cause. I suspect that Hassan
and Chuck are nto using anti-resource-locking while Lyallex is.

I've never had this problem myself because I don't try to generate
static content dynamically :)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkoxKw0ACgkQ9CaO5/Lv0PCqigCeLDj4JIz/5Q/3RcCTQg6hiJQ5
Y7EAoLwc3qisk1loM3+zq2AdfX6vD3Lm
=WmdG
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Mark Thomas <ma...@apache.org>.
Lyallex wrote:
> 2009/6/11 Caldarale, Charles R <Ch...@unisys.com>:
>>> From: Hassan Schroeder [mailto:hassan.schroeder@gmail.com]
>>> Subject: Re: Loading dynamically created content: An old chestnut but
>>> still a problem.
>>>
>>> Then I copied a random example.gif image to the ROOT directory
>>> and entered http://localhost:8080/example.gif in my address bar.
>>> And there it is in my browser.
>> Just to confirm that there's no long-term caching, I extended the above by starting Tomcat, loaded the home page in Firefox, replaced tomcat.gif by one of Bill the Cat with the name tomcat.gif, refreshed the page with F5, and got the revised, much uglier image in the upper left corner.
>>
>>  - Chuck
> 
> OK, all very nice ... I just tried this. The server was running and my
> application was up and working.
> I copied an image into the ROOT directory then tried to access it like
> so http://localhost/main.jpg and got a 404 not found.
> 
> I stopped and restarted the server (very important this) and tried the
> same request again and the image loaded.
> 
> I'm not imagining this. It is a fact. On my setup (tomcat 6.0.16.
> jdk1.6.0_03, Windows XP SP 2) I cannot load images that have been
> written to disk after the server starts ... sorry if this offends you
> in some way, it's driving ME nuts especially as you all seem to have
> no trouble with this. I'm almost tempted to load the app onto the live
> server and see if it works there. .. no, that way lies madness.

This all all a expected side-effect of using the anti resource locking
features.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Loading dynamically created content: An old chestnut but still a problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Lyallex [mailto:lyallex@gmail.com]
> Subject: Re: Loading dynamically created content: An old chestnut but
> still a problem.
> 
> I'm not imagining this. It is a fact. On my setup (tomcat 6.0.16.
> jdk1.6.0_03, Windows XP SP 2) I cannot load images that have been
> written to disk after the server starts ...

Both Hassan and I were using a stock Tomcat 6.0.20 (mine was on Vista 64).  Try it with a 6.0.20 clean installation, and then compare configs between your 6.0.16 and 6.0.20 versions to see what you've changed that is preventing the normal behavior.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Lyallex <ly...@gmail.com>.
2009/6/11 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Hassan Schroeder [mailto:hassan.schroeder@gmail.com]
>> Subject: Re: Loading dynamically created content: An old chestnut but
>> still a problem.
>>
>> Then I copied a random example.gif image to the ROOT directory
>> and entered http://localhost:8080/example.gif in my address bar.
>> And there it is in my browser.
>
> Just to confirm that there's no long-term caching, I extended the above by starting Tomcat, loaded the home page in Firefox, replaced tomcat.gif by one of Bill the Cat with the name tomcat.gif, refreshed the page with F5, and got the revised, much uglier image in the upper left corner.
>
>  - Chuck

OK, all very nice ... I just tried this. The server was running and my
application was up and working.
I copied an image into the ROOT directory then tried to access it like
so http://localhost/main.jpg and got a 404 not found.

I stopped and restarted the server (very important this) and tried the
same request again and the image loaded.

I'm not imagining this. It is a fact. On my setup (tomcat 6.0.16.
jdk1.6.0_03, Windows XP SP 2) I cannot load images that have been
written to disk after the server starts ... sorry if this offends you
in some way, it's driving ME nuts especially as you all seem to have
no trouble with this. I'm almost tempted to load the app onto the live
server and see if it works there. .. no, that way lies madness.

lyallex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Loading dynamically created content: An old chestnut but still a problem.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Hassan Schroeder [mailto:hassan.schroeder@gmail.com]
> Subject: Re: Loading dynamically created content: An old chestnut but
> still a problem.
> 
> Then I copied a random example.gif image to the ROOT directory
> and entered http://localhost:8080/example.gif in my address bar.
> And there it is in my browser.

Just to confirm that there's no long-term caching, I extended the above by starting Tomcat, loaded the home page in Firefox, replaced tomcat.gif by one of Bill the Cat with the name tomcat.gif, refreshed the page with F5, and got the revised, much uglier image in the upper left corner.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Hassan Schroeder <ha...@gmail.com>.
On Wed, Jun 10, 2009 at 11:48 PM, Lyallex<ly...@gmail.com> wrote:

>> I know its completely possible to add images the root of a Web-App folder
>> after deployment and have Tomcat "see" them.
>
> Great, any idea how ?
> Others here seem to think that the DefaultServlet will not serve
> content that is uploaded after the server starts and this is the
> behaviour I'm seeing

I don't know who these "others" are, but I just downloaded a fresh
copy of 6.0.20, untarred and started it in its default configuration
(using $CATALINA_HOME/bin/catalina.sh run) and confirmed that
the ROOT webapp welcome page appeared in my browser.

Then I copied a random example.gif image to the ROOT directory
and entered http://localhost:8080/example.gif in my address bar.
And there it is in my browser.

So I think the question is more "what changes have you made to
break the normal behavior?"  :-)

For completeness, this is on a Mac/OS X (10.5.6) running the Mac
HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

FWIW,
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Lyallex <ly...@gmail.com>.
2009/6/10 Jonathan Mast <jh...@gmail.com>:
> Ok, so this approach of writing to disk after reading the database is not
> working at all.  I thought you were saying previously that was working up to
> a point, but then failing for new products.
>
> I know its completely possible to add images the root of a Web-App folder
> after deployment and have Tomcat "see" them.

Great, any idea how ?
Others here seem to think that the DefaultServlet will not serve
content that is uploaded after the server starts and this is the
behaviour I'm seeing

I'd be really interested to know how it's done

> Are you by chance running Tomcat behind Apache Httpd or some other server?

Nope, Tomcat runs standalone on port 80 and serves all content

thanks

lyallex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Jonathan Mast <jh...@gmail.com>.
Ok, so this approach of writing to disk after reading the database is not
working at all.  I thought you were saying previously that was working up to
a point, but then failing for new products.

I know its completely possible to add images the root of a Web-App folder
after deployment and have Tomcat "see" them.

Are you by chance running Tomcat behind Apache Httpd or some other server?


On Wed, Jun 10, 2009 at 1:10 PM, Lyallex <ly...@gmail.com> wrote:

> Hi
>
> I'll try to explain in as few words as possible.
>
> When I upload a new product I store the image data and the text in the
> database. I did this to try and separate the data from the application
>  with the intention of eventually having the data reside on a separate
> device optimised for serving data ... well that was my original
> thinking anyway.
>
> At the moment, when I load an image I use a proxy servlet and extract
> the imageid from the 'Product' (p below)
>
> <img
> src="ImageProxy?<%=WebConstants.IMAGE_ID%>=<%=p.calculateImageId()%>...
> etc '/>
>
> This gets the image from the database and displays it in the page.
>
> This is clunky and slow and the image is not cached by the browser
>
> So, when a user views an item detail I do something like this
>
> getProductDetails?productId='whatever'
>
> In the GetProductDetails servlet I check the disk cache to see if the
> image is there, if not I get it from the database an write it to the
> cache, just one database access as opposed to many, the next time
> anyone sees that item the images are already cached.
>
> now, in the jsp I can use <img
> src="imagecache/<%=p.getProductId()%>_thumb.jpg"  ...' etc/>
>
> In other words, as opposed to getting an anonymous byte stream and
> displaying it in the browser I'm now accessing a named image and the
> browser caches it. It all works beautifully apart from the fact that
> it appears the DefaultServlet will not load resources that have been
> written to disk after the server has been started. If I restart the
> server I can see my images, but only the ones loaded thus far ...
>
> Anyway, I'm currently looking at the serveResource() method in the
> DefaultServlet to try and figure out if it is possible to configure it
> to load resoures that have appeared after the server has started ...
> it doesn't look like it is possible which is slightly depressing ...
> unless of course I am missing something.
>
> Surely this is not an unusual requirement, how do others deal with
> serving up images that have been uploaded after the server has
> started.
>
> Anyway
>
> Thanks for taking the time to reply
> lyallex
>
>
> 2009/6/10 Jonathan Mast <jh...@gmail.com>:
> > So you are actually storing the image data in the database, as opposed to
> > the filepath? interesting...
> >
> > So your webapp accesses the image data as needed and writes it to
> imagecache
> > dir?  Is this feature not working? i don't understand what exactly the
> issue
> > is that you are having.  please explain.
> >
> >
> >
> > On Wed, Jun 10, 2009 at 9:41 AM, Lyallex <ly...@gmail.com> wrote:
> >
> >> apache-tomcat-6.0.16
> >> jdk1.6.0_03
> >>
> >> Dev box : Windows
> >> Deployment box: Linux
> >>
> >> Hi
> >>
> >> I've read some other posts that seem to be asking similar questions
> >> but I can't find the answer so far.
> >> maybe someone here would be kind enough to give me a hint
> >>
> >> I have a retail application that stores the product images in a
> database.
> >> Each product can have many images and products are being uploaded all
> the
> >> time.
> >>
> >> Fetching images from the database every time results in a clunky page
> >> load so I want to cache the images to disk
> >> the first time an item is accessed my cache manager checks the disk
> >> cache to see if images for that item are available.
> >> If not it loads them onto the disk.
> >> this happens in the servlet that serves the item details up so the
> >> images are in the disk cache before the request is forwarded to the
> >> view (jsp)
> >> In the jsp I access the images from the disk cache.
> >>
> >> The problem is, the first time I access the item details the images
> >> are written to the cache which resides directly under the
> >> context root but they are not loaded in the view.
> >> If I restart tomcat the images disply fine so I know all the caching
> >> is working correctly.
> >>
> >> I can't restart tomcat everytime I upload a new product so how can I
> >> force tomcat to recognise the new images 'on the fly' so as to speak?
> >> The application is running as the ROOT application on the server and
> >> is the only application being served.
> >>
> >> An example image might be
> >> ../apache-tomcat-6.0.16/webapps/ROOT/imagecache/8000030_main.jpg
> >> (example)
> >>
> >> I'm quite happy that the imagecache is deleted everytime I redeploy
> >> the application because the application is starting to stabilise and
> >> once I have this last problem ironed out
> >> I will only be doing irregular maintenance. The faster loading of
> >> images is more than enough compensation.
> >>
> >> I can't use symbolic links to place the imagecache outside the
> >> application space because I develop on Windows and deploy to Linux
> >> (historical, nothing I can do about it)
> >>
> >> Any ideas much appreciated.
> >>
> >>
> >> Many thanks
> >> lyallex
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Lyallex <ly...@gmail.com>.
Hi

I'll try to explain in as few words as possible.

When I upload a new product I store the image data and the text in the
database. I did this to try and separate the data from the application
 with the intention of eventually having the data reside on a separate
device optimised for serving data ... well that was my original
thinking anyway.

At the moment, when I load an image I use a proxy servlet and extract
the imageid from the 'Product' (p below)

<img src="ImageProxy?<%=WebConstants.IMAGE_ID%>=<%=p.calculateImageId()%>...
etc '/>

This gets the image from the database and displays it in the page.

This is clunky and slow and the image is not cached by the browser

So, when a user views an item detail I do something like this

getProductDetails?productId='whatever'

In the GetProductDetails servlet I check the disk cache to see if the
image is there, if not I get it from the database an write it to the
cache, just one database access as opposed to many, the next time
anyone sees that item the images are already cached.

now, in the jsp I can use <img
src="imagecache/<%=p.getProductId()%>_thumb.jpg"  ...' etc/>

In other words, as opposed to getting an anonymous byte stream and
displaying it in the browser I'm now accessing a named image and the
browser caches it. It all works beautifully apart from the fact that
it appears the DefaultServlet will not load resources that have been
written to disk after the server has been started. If I restart the
server I can see my images, but only the ones loaded thus far ...

Anyway, I'm currently looking at the serveResource() method in the
DefaultServlet to try and figure out if it is possible to configure it
to load resoures that have appeared after the server has started ...
it doesn't look like it is possible which is slightly depressing ...
unless of course I am missing something.

Surely this is not an unusual requirement, how do others deal with
serving up images that have been uploaded after the server has
started.

Anyway

Thanks for taking the time to reply
lyallex


2009/6/10 Jonathan Mast <jh...@gmail.com>:
> So you are actually storing the image data in the database, as opposed to
> the filepath? interesting...
>
> So your webapp accesses the image data as needed and writes it to imagecache
> dir?  Is this feature not working? i don't understand what exactly the issue
> is that you are having.  please explain.
>
>
>
> On Wed, Jun 10, 2009 at 9:41 AM, Lyallex <ly...@gmail.com> wrote:
>
>> apache-tomcat-6.0.16
>> jdk1.6.0_03
>>
>> Dev box : Windows
>> Deployment box: Linux
>>
>> Hi
>>
>> I've read some other posts that seem to be asking similar questions
>> but I can't find the answer so far.
>> maybe someone here would be kind enough to give me a hint
>>
>> I have a retail application that stores the product images in a database.
>> Each product can have many images and products are being uploaded all the
>> time.
>>
>> Fetching images from the database every time results in a clunky page
>> load so I want to cache the images to disk
>> the first time an item is accessed my cache manager checks the disk
>> cache to see if images for that item are available.
>> If not it loads them onto the disk.
>> this happens in the servlet that serves the item details up so the
>> images are in the disk cache before the request is forwarded to the
>> view (jsp)
>> In the jsp I access the images from the disk cache.
>>
>> The problem is, the first time I access the item details the images
>> are written to the cache which resides directly under the
>> context root but they are not loaded in the view.
>> If I restart tomcat the images disply fine so I know all the caching
>> is working correctly.
>>
>> I can't restart tomcat everytime I upload a new product so how can I
>> force tomcat to recognise the new images 'on the fly' so as to speak?
>> The application is running as the ROOT application on the server and
>> is the only application being served.
>>
>> An example image might be
>> ../apache-tomcat-6.0.16/webapps/ROOT/imagecache/8000030_main.jpg
>> (example)
>>
>> I'm quite happy that the imagecache is deleted everytime I redeploy
>> the application because the application is starting to stabilise and
>> once I have this last problem ironed out
>> I will only be doing irregular maintenance. The faster loading of
>> images is more than enough compensation.
>>
>> I can't use symbolic links to place the imagecache outside the
>> application space because I develop on Windows and deploy to Linux
>> (historical, nothing I can do about it)
>>
>> Any ideas much appreciated.
>>
>>
>> Many thanks
>> lyallex
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Loading dynamically created content: An old chestnut but still a problem.

Posted by Jonathan Mast <jh...@gmail.com>.
So you are actually storing the image data in the database, as opposed to
the filepath? interesting...

So your webapp accesses the image data as needed and writes it to imagecache
dir?  Is this feature not working? i don't understand what exactly the issue
is that you are having.  please explain.



On Wed, Jun 10, 2009 at 9:41 AM, Lyallex <ly...@gmail.com> wrote:

> apache-tomcat-6.0.16
> jdk1.6.0_03
>
> Dev box : Windows
> Deployment box: Linux
>
> Hi
>
> I've read some other posts that seem to be asking similar questions
> but I can't find the answer so far.
> maybe someone here would be kind enough to give me a hint
>
> I have a retail application that stores the product images in a database.
> Each product can have many images and products are being uploaded all the
> time.
>
> Fetching images from the database every time results in a clunky page
> load so I want to cache the images to disk
> the first time an item is accessed my cache manager checks the disk
> cache to see if images for that item are available.
> If not it loads them onto the disk.
> this happens in the servlet that serves the item details up so the
> images are in the disk cache before the request is forwarded to the
> view (jsp)
> In the jsp I access the images from the disk cache.
>
> The problem is, the first time I access the item details the images
> are written to the cache which resides directly under the
> context root but they are not loaded in the view.
> If I restart tomcat the images disply fine so I know all the caching
> is working correctly.
>
> I can't restart tomcat everytime I upload a new product so how can I
> force tomcat to recognise the new images 'on the fly' so as to speak?
> The application is running as the ROOT application on the server and
> is the only application being served.
>
> An example image might be
> ../apache-tomcat-6.0.16/webapps/ROOT/imagecache/8000030_main.jpg
> (example)
>
> I'm quite happy that the imagecache is deleted everytime I redeploy
> the application because the application is starting to stabilise and
> once I have this last problem ironed out
> I will only be doing irregular maintenance. The faster loading of
> images is more than enough compensation.
>
> I can't use symbolic links to place the imagecache outside the
> application space because I develop on Windows and deploy to Linux
> (historical, nothing I can do about it)
>
> Any ideas much appreciated.
>
>
> Many thanks
> lyallex
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>