DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > The one where I try ColdFusion 9 ORM secondary cache and decide it's awesome

The one where I try ColdFusion 9 ORM secondary cache and decide it's awesome

Sam Farmer user avatar by
Sam Farmer
·
Apr. 19, 11 · Java Zone · News
Like (0)
Save
Tweet
7.42K Views

Join the DZone community and get the full member experience.

Join For Free

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:

  1. added a version field which would definitively show when Hibernate had updated the record (another very cool underused feature)
  2. added my own getter to verify that secondary cache returns data via the cfc and not just flat

Now there are four types of cacheuse, here are the differences:

  • transactional cache is updated on the update statement and the next request of the data will get it straight from cache and not run a select
  • nonstrict-read-write Cache is updated on the first select after data is updated or inserted
  • read-write I could not get this to work with caching (docs say its the worst performing anyway)
  • read-only Only works with data that will not be updated. Produces an error if you attempt to update or insert records. (Marc Esher wrote a long, funny blog entry about using secondary cache to cache for a read-only view)

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.




Cache (computing) Awesome (window manager)

Published at DZone with permission of Sam Farmer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Migrating From Heroku To Render
  • Why Performance Projects Fail
  • This Is How You Give Good Feedback at Work
  • Cloud-Based Integrations vs. On-Premise Models

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo