Description

Converts a ColdFusion array, CFC, DateTime object, Java object, query, or structure into a serializable binary object and optionally saves the object in a file.

Returns

A serializable binary representation of the object.

Category

Other functions

Function syntax

ObjectSave(object[, filePath])

See also

ObjectLoad

Parameters

Parameter

Description

object

The complex object, such as a query or CFC, that will be serialized.

filePath

The path of the file in which to save the serialized data.

Usage

This function is useful for handling dynamic data that has a relatively long period of usefulness and takes substantial time or resources to obtain. It lets you save the data in a file and use it in multiple application instances. For example, you can create a CFC that stores a query that takes long time to run and retrieves infrequently updated data. If you use the ObjectSave function to initially save the CFC as a file, and deserialize the CFC file on future application starts, you can improve application performance.

Example

<h3>Saving and loading an object</h3> 

<!--- Create the component object. ---> 
<cfobject component="tellTime" name="tellTimeObj"> 
<!--- Save the component object to a file. ---> 
<cfset ObjectSave(tellTimeObj, "data.out")/> 

<!--- Load the component object again. ---> 
<cfset ObjLoaded = ObjectLoad("data.out") > 

<!--- Invoke the methods from loaded objects. ---> 
<cfinvoke component="#ObjLoaded#" method="getLocalTime" returnvariable="localTime"> 
<cfinvoke component="#ObjLoaded#" method="getUTCTime" returnvariable="UTCTime"> 
<!--- Display the results. ---> 
<h3>Time Display Page</h3> 
<cfoutput> 
Server's Local Time: #localTime#<br> 
Calculated UTC Time: #UTCTime# 
</cfoutput>

Note:

ColdFusion skips any object that does not support serialization. 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy