I have a java web application that generates and displays graphical pictures based upon some user parameters.
I used to store the graphics in the Session map, but that is generally not a good idea (you want to keep the session data as small as possible).
So instead, I only want to generate a file on the server and refer to it via an URL that I will store in the session map.
The question is: How can I remove the generated file after the session expires? I do not want to be stuck with a lot of graphics and I do not like the idea of just cleaning the folder with generated graphics at midnight as a user may be using my website at that time.
It could also be that there are other means to accomplish what I want. I'm interested what's the best practice for this kind of retrieval from the server.