Hi there,
I was testing out the XWiki Enterprise 3.5 release and I noticed that
the temporary files folder under my Tomcat 7 kept growing while I was
testing out XWiki.
I had added a number of jpg attachments to a page that was using the
{{photoalbum}} macro to display them.
However, I found that this causes a number of download requests with the
width parameter set, which seems to cause a new temporary file to be
created for each request. It seems that even though the original image
is cached it re-creates a new XWikiAttachmentContent thumbnail from
those original bytes each time, causing multiple DiskFileItems to be
created.
Looking through the code for XWikiAttachmentContent it does set the
deleteOnExit() for the DiskFileItem's store location file, but this file
then will only be deleted when the JVM is shutdown.
If multiple pages have many images each and they are being displayed in
the photoalbum macro, then this creates a problem with diskspace being
used up until the server is restarted.
(And in my case for some reason stopping Tomcat via the service icon
terminates the JVM in a way that doesn't cause the deleteOnExit() to be
called as all of the temporary files are left behind after Tomcat is
stopped)
How can we stop all these temporary files from becoming a problem with a
long running web application?
There may be a better way, but I tried hacking around with the 3.5
platform on my github account and created a component to fix the problem
by deleting files that had their DiskFileItem no longer being referenced:
Modified 3.5 platform (mainly XWikiAttachmentContent)
https://github.com/jamiemaher/xwiki-platform/tree/feature-tempfiles-3.5
Temporary Files provider component referenced by the XWikiAttachmentContent:
https://github.com/jamiemaher/xwiki-tempfiles-component
It seems to work pretty well, although there seem to be some files that
don't seem to be reclaimed, although I haven't tracked down if it's
because they are also in the regular xwiki cache as well.
Thanks,
Jamie