Question
Cloning CFC instances In Memory
We have a framework which can create hundreds of CFCs per
page request. Most of the request time is used when a
CreateObject("component", "....") is executed. This time is large
because template caching must be disabled for other reasons. When
the cache is enabled, the execution time is reduced significantly,
sometimes by a factor of 5 or more.
To compensate, I'd like to keep a prototype of each CFC I will be creating in memory, and then clone the one that currently resides in memory to avoid disk I/O. Note that I don't want a "deep copy" of a CFC because they should be empty prototypes anyways.
This is possible in Java using the Object.clone() (deep copy) method or perhaps Object.getClass().newInstance() (empty copy), of which the latter approach is the one I'd like to take.
I've tried writing a simple function in Java to do this:
public static createFromInstance(Object obj) {
...
return obj.getClass().newInstance();
...
}
but trying to use this method within ColdFusion gives undefined variables exceptions.
We are using CF 6.1, but we may consider a move to 7. Perhaps using the CFCProxy class in 7.0.1 will work. Has anyone tried this method or has anyone written a Java or ColdFusion solution using 6.1? Can anyone explain the underlying mechanism of how CFCs map to Java objects, and how it might be possible to clone them?
To compensate, I'd like to keep a prototype of each CFC I will be creating in memory, and then clone the one that currently resides in memory to avoid disk I/O. Note that I don't want a "deep copy" of a CFC because they should be empty prototypes anyways.
This is possible in Java using the Object.clone() (deep copy) method or perhaps Object.getClass().newInstance() (empty copy), of which the latter approach is the one I'd like to take.
I've tried writing a simple function in Java to do this:
public static createFromInstance(Object obj) {
...
return obj.getClass().newInstance();
...
}
but trying to use this method within ColdFusion gives undefined variables exceptions.
We are using CF 6.1, but we may consider a move to 7. Perhaps using the CFCProxy class in 7.0.1 will work. Has anyone tried this method or has anyone written a Java or ColdFusion solution using 6.1? Can anyone explain the underlying mechanism of how CFCs map to Java objects, and how it might be possible to clone them?