The ImagePlugin re-creates thumbnail temporary files on every request, despite the fact that the original image and thumbnail image content may be cached.
The ImagePlugin.downloadImageFromCache method caches the thumbnail after is is resized by the shrinkImage() method, but on subsequent requests the
XWikiAttachment is cloned and the .setContent(InputStream,int) method set from the cached data which causes a new temporary file to be created every time.
Right now it serves the bytes to the client by:
- Getting the image bytes from the cache
- writing those cached bytes out to disk from the cache by re-creating a new temporary file (unless the memory file size threshold was not reached - 10kb)
- Re-reading those image bytes from the file via the DiskFileItem to serve to the servlet response.
If a page has multiple images (eg. 20+ images) shown as thumbnails then the disk space consumed can start to grow fairly quickly.
Could the cached bytes be used directly instead of re-creating a new temporary file?