Using Flash RAM

There are several ways to interact with the ColdBox Flash RAM:

  • Using the flash scope object (Best Practice)
  • Using the persistVariables() method from the super type and ColdBox Controller
  • Using the persistence arguments in the setNextEvent() method from the super type and ColdBox Controller.

All of these methods interact with the Flash RAM object but the last two methods not only place variables in the temporary storage bin but actualy serialize the data into the Flash RAM storage immediately. The first approach queues up the variables for serialization and at the end of a request it serializes the variables into the correct storage scope, thus saving precious serialization time. In the next section we will learn what all of this means.

Flash Scope Object

The flash scope object is our best practice approach as it clearly demarcates the code that the developer is using the flash scope for persistence. Any flash scope must inherit from our AbstractFlashScope and has access to several key methods that we will cover in this section. However, let's start with how the flash scope stores data:

  1. The flash persistence methods are called for saving data, the data is stored in an internal temporary request bin and awaiting serialization and persistence either through relocation or termination of the request.
  2. If the flash methods are called with immediate save arguments, then the data is immediately serialized and stored in the implementation's persistent storage.
  3. If the flash's saveFlash() method is called then the data is immediately serialized and stored in the implementation's persistent storage.
  4. If the application relocates via setNextEvent() or a request finalizes then if there is data in the request bin, it will be serialized and stored in the implementation's storage.

Caution By default the Flash RAM queues up serializations for better performance, but you can alter the behavior programmatically or via the configuration file.

Info If you use the persistVariables() method or any of the persistence arguments on the setNextEvent() method, those variables will be saved and persisted immediately.

To review the Flash Scope methods, please go to the API and look for the correct implementation or the AbstractFlashScope.

Info Please note that the majority of a Flash scope methods return itself so you can concatenate method calls. Below are the main methods that you can use to interact with the Flash RAM object:


Clears the temporary storage bin



Clears the persistence flash storage implementation



any discard([string keys=''])

Discards all or some keys from flash storage. You can use this method to implement flows.

// discard all flash variables

// dicard some keys


boolean exists(string name)

Checks if a key exists in the flash storage

if( flash.exists('notice') ){
 // do something


any get(string name, [any default])

Get's a value from flash storage and you can even pass a default value if it does not exist.

// Get a flash key that you know exists
cardID = flash.get("cardID");

// Render some flash content
<div class="notice">#flash.get("notice","")#</div>


Get a list of all the objects in the temp flash scope.

Flash Keys: #structKeyList( flash.getKeys() )#


Get a reference to the permanent storage implementation of the flash scope.

<cfdump var="#flash.getFlash()#">


Get the flash temp request storage used throughout a request until flashed at the end of a request.

<cfdump var="#flash.getScope()#">


Check if the flash scope is empty or not

<cfif !flash.isEmpty()>


any keep([string keys=''])

Keep all or a single flash temp variable alive for another relocation. Usually called from interceptors or event handlers to create conversations and flows of data from event to event.

function step2(event){
    // keep variables for step 2 wizard

    // keep al variables


any persistRC([string include=''], [string exclude=''], [boolean saveNow='false'])

Persist keys from the ColdBox request collection into flash scope. If using exclude, then it will try to persist the entire request collection but excluding certain keys. Including will only include the keys passed from the request collection.

// persist some variables that can be reinflated into the RC upon relocation

// persist all RC variables using exclusions that can be reinflated into the RC upon relocation

// persist some variables that can be reinflated into the RC upon relocation and serialize immediately


any put(string name, any value, [boolean saveNow='false'], [boolean keep='true'], [boolean inflateToRC=FROMConfig], [boolean inflateToPRC=FROMConfig], [boolean autoPurge=FROMConfig)

This is the main method to place data into the flash scope. You can optionally use the arguments to save the flash immediately, inflate to RC or PRC on the next request and if the data should be auto purged for you. You can also use the configuration settings to have a consistent flash experience, but you can most certainly override the defaults. By default all variables placed in flash RAM are automatically purged in the next request once they are inflated UNLESS you use the keep() methods in order to persist them longer or create flows. However, you can also use the autoPurge argument and set it to false so you can control when the variables will be removed from flash RAM. Basically a glorified ColdFusion scope that you can use.

// persist some variables that can be reinflated into the RC upon relocation

// put and serialize immediately.

// put and mark them to be reinflated into the PRC only

// put and disable autoPurge, I will remove it when I want to!


any putAll(struct map, [boolean saveNow='false'], [boolean keep='true'], [boolean inflateToRC='[runtime expression]'], [boolean inflateToPRC='[runtime expression]'], [boolean autoPurge='[runtime expression]'])

Same as the put() method but instead you pass in an entire structure of name-value pairs into the flash scope.

var map = {
    addressData = rc.address,
    userID = securityService.getUserID(),
    loggedIn = now()

// put all the variables in flash scope as single items

// Use them later
if( flash.get("loggedIn") ){



any remove(string name, [boolean saveNow='false'])

Remove an object from the temporary flash scope so when the flash scope is serialized it will not be serialized. If you would like to remove a key from the flash scope and make sure your changes are reflected in the persistence storage immediately, use the saveNow argument.

// mark object for removal

// mark object and remove immediately from flash storage


Remove the entire flash storage. We recommend using the clearing methods instead.


Save the flash storage immediately. This process looks at the temporary request flash scope and serializes if it needs to and persists to the correct flash storage on demand.

Info We would advice to not overuse this method as some storage scopes might have delays and serializations



Get the number of the items in flash scope

You have #flash.size()# items in your cart!

More Examples

// handler code:
function saveForm(event){
    // save post
    flash.put("notice","Saved the form baby!");
    // relocate to another event
function show(event){
    // Nothing to do with flash, inflating by flash object automatically

// User/show.cfm template using if statements
<cfif flash.exists("notice")>
    <div class="notice">#flash.get("notice")#</div>

// User/show.cfm using defaults
<div class="notice">#flash.get(name="notice",default="")</div>

results matching ""

    No results matching ""