1 person found this helpful
Question 1: I would use CreateUUID() for the file name uniqueness and store this in the session scope. I don't like using the actual session id as I don't like the idea of using something out of my control for this sort of thing. Also, your logic would have to account for the session setting options in the CF administration.
Question 2: There is an onSessionEnd event in the latest CF versions, but I have not used it. I would store an array in the application scope with expiration information. When the item expires, deleted it from the array. Then have a recurring scheduled event delete all the files not in the current array, maybe once an hour or so.
You're correct, I don't have control over the CF Admin, so the UUID is probably the best idea. As for the deleting, perhaps I could just write something to delete any files older than an hour whenever the page is loaded.
That'll work too. That was actually my original thought but then I assumed you wanted something more complex.
Complex is tough where I work because I'm not allowed to create things like chron jobs. Unless it happens in the CF application itself, it ain't happening.
Then maybe something like this in your onRequestStart or onSessionStart of your application.cfc:
<cfset variables.doCleanup = false />
<cflock name="myCHRON" timeout="15" throwontimeout="no" type="exclusive">
<cfif NOT structKeyExists(application,"myNextCleanupRun") or application.myNextCleanupRun LTE now()>
<cfset variables.doCleanup = true />
<cfset application.myNextCleanupRun = dateAdd('h',1,now()) />