I’m writing an interface to the FlashScope and noticed two records were being inserted. Tracing back through the system I discovered ColdBox is saving the FlashScope twice. Once when the “persistVariables()” method is called within the Controller and again right before the redirect.
Is this the desired behavior?
// WHEN SETNEXTEVENT() IS CALLED
project\core\model\FlashScope.cfc:107)
coldbox_fork\system\web\flash\AbstractFlashScope.cfc:202)
coldbox_fork\system\web\Controller.cfc:650) <<<<<< putAll(map={},saveNow=true);
coldbox_fork\system\web\Controller.cfc:437)
coldbox_fork\system\FrameworkSupertype.cfc:235)
project\core\includes\UDF.cfm:39)
project\gui\handlers\Login.cfc:99)
// JUST BEFORE REDIRECT
project\core\model\FlashScope.cfc:107)
coldbox_fork\system\web\Controller.cfc:448) <<<<<< saveFlash();
coldbox_fork\system\FrameworkSupertype.cfc:235)
coldbox_fork\system\web\Controller.cfc:704)
coldbox_fork\system\web\Controller.cfc:591)
coldbox_fork\system\Coldbox.cfc:243)
We introduced the flash interface in 3.0, before it was just via the persistVariables() method and the persist arguments on relocations. For backwards compatibility, those two approaches are still valid, but they save the variables IMMEDIATELY to reflect behavior as it was before.
Now, on relocations, is when we automatically trigger the saveNow() on the flash scope for you. However, if you are not relocating but just setting data on the flash scope and then rendering a page, you will need to call save explicitly.
Hopefully, by 3.1 we can remove the persistVariables() method, as our preferred approach is via the flash object.