Is there any way to cleanup temporary files/directories after sending response?
I have application which create temporary directory with some files (for
example PDF file) in processing of request. I need to cleanup whole temporary
directory after file is sent. I thought that
phase/method should be the right place for doing such thing, but this method is
called before data are actualy send via
sendResponse() method. After sendResponse() there's no way to call
some cleanup code and I cannot delete temporary directory before
sendResponse() method call, because file to be send is stored in it
(also I cannot move it elsewhere for same reason). This application could send
from hundred to thousands files per day and therefore volume of this temporary
directories/files could be huge (lets say in scale of GB).
I can delete it periodicaly from cron daemon of course, but this brings other troubles like, how recognize already downloaded files from files still being actively downloaded (I know, that this is not a problem on unix-like systems, where files are removed only after they are closed from all processes, but I think this is not clean solution).
Can someone give me advice, or show me some way to do this in clearly?
- Member | 124
Hey, I'm just solving the same issue and came into the same solution –
register Application::onShutdown(). However, I think this is a non-elegant
solution as many FileResponses are of a teporary file that can be deleted
Do you think that it would be useful to add some “deleteAfterSending” option to FileResponse? Please give opinions if this makes sense or not to you.