I've pretty much overlooked the secondary cache for ORM and, having now played with it, I've realized what a big feature and performance enhancer this is.
In short with secondary cache on ColdFusion can get data from ehCache instead of the database. Set up ColdFusion 9.0.1 and you can share entity data across both ColdFusion instances and servers!
Let backtrack and take a look at a basic set up:
Application.cfc
component {
this.datasource = "cacheFun";
this.ormEnabled = true;
this.ormSettings = {secondaryCacheEnabled=true, logsql=true};
}
To turn on secondary cache set secondaryCacheEnabled to true (the default is false). In this example I have also turned logsql to true*. Now lets look at our persistent cfc:
User.cfc
component persistent="true" cachename="userCache" cacheuse="transactional" {
property name="id" column="id" ormtype="int" fieldtype="id" generated="always" generator="native";
property name="firstname" ormtype="string";
property name="lastname" ormtype="string";
property name="version" fieldtype="version" datatype="int" ;
function getLastName() {
return uCase (variables.lastname);
}
}
That really is it. The two cache attributes tell ColdFusion to use secondary cache for this data. From now on a call like:
user = entityLoad("User", {id=1}, true);
will use the secondary cache when possible.
To help work out what secondary cache is doing I did two things in User.cfc:
Now there are four types of cacheuse, here are the differences:
I'm going to look more into secondary cache and hopefully come up with real examples but for now I know two things: 1) its very powerful, 2) its very easy to use.
* If ColdFusion is started from the Builder server panel the console tab will display all the SQL Hibernate produces. I used it to see when Hibernate went to cache and when the database.
By: Raymond Camden 02/07/2011 10:51 PM