I’ve got a Coldbox app that I’m trying to migrate over from explicitly using the session
scope to using the flash
object. However, I’ve been experiencing some unpredictable behavior when attempting to persist data in flash
using an ajax request and then retrieving it on a page refresh. Here’s what my code looks like:
I’m currently using ACF 2018.
I persist the data in Flash RAM via an ajax call to a handler. The handler looks like this:
function save( event, rc, prc ) {
param rc.key = "";
param rc.data = {};
if ( isJson( rc.data ) ) {
rc.data = deSerializeJson( rc.data );
}
// if we have a key and some data to store, persist it in Flash RAM
if ( isSimpleValue( rc.key ) && isStruct( rc.data ) ) {
flash.put(
name = rc.key,
value = rc.data,
autoPurge = false,
saveNow = true,
inflateToRC = false
);
}
return {
"key": rc.key,
"data": rc.data
};
}
My retrieval handler looks like this:
function index( event, rc, prc ){
var data = flash.get( "myKey", {
"search" : "",
"statusId" : "",
"categoryId" : "",
"hideChildren": ""
} );
writeDump( data );
}
The first execution of my ajax handler works. I set statusId
to a value of 1 and I can see the ajax response returns the correct value. When I refresh the page, I can see my intended data appear in the dump. However, on subsequent executions of the ajax handler, the Flash RAM doesn’t persist the updated data.
When I dump out the session scope after the first ajax call, this is what I see:
On the subsequent ajax request, I updated statusId
to a value of 2. I confirmed that I could see the proper value from the ajax response. However, when I refresh the handler I still see statusId
has a value of 1.
I would have expected the value to be 2. Am I missing something? Do I need to do anything special to have flash
overwrite existing data?