In Phoenix Next Week? Come See a Preview of My cf.Objective Caching Presentation

If you happen to be in the Phoenix area on Wednesday, January 25th, stop on by the University of Advancing Technology at 6:30 pm to catch a preview of my upcoming cf.Objective presentation: Ten Steps to Move Your Use of Caching Beyond the Basics. Here's a short description of the presentation:

We all know that caching plays an important part of any performant and scalable application architecture and that with ColdFusion 9 caching is easier than ever. This session explores 10 steps you can take to move your use of caching beyond what ColdFusion provides out of the box.

*Please note that this presentation won't be recorded/streamed. You have to be there in person to see it. Normally I'm all for recording and streaming, but since this is a preview of a talk I'll be giving at an upcoming conference, I want to limit the audience out of respect to those attending the conference.

How I got Started with ColdFusion

Steve Bryant started a meme encouraging those involved with ColdFusion to post their personal story of how they got involved with the language. Here's mine.

I first fell in love with computers during the summer of 1982. I was 10 years old and my parents signed me up for a summer program to teach kids Basic programming. I spent that summer learning to hack Basic on a terminal connected to a mainframe. The following year my elementary school got a dozen or so Apple IIe computers and I was hooked. From there I got my first home computer – a Commodore Vic 20 with 2.5 k of RAM. I still remember sitting in my room painstakingly typing in game code from the latest issue of Compute magazine. I'd often leave the computer running for days as I didn't have any way to save the programs at the time and retyping everything would take me hours. I'm pretty sure this is where my debugging skills were forged as I hunted through program code trying to find the typos I had made while transcribing from the magazines. It wasn't long before I scraped enough money together to buy a tape drive, allowing me to save my programs. As technology marched forward, so did I. My next home computer was a Commodore 64. I must have spent thousands of hours on that machine programming, playing games, and immersing myself in the world of computers.

When I got to high school, Apple was out and IBM was in. My high school didn't allow freshmen to take computer classes, so I had to wait until 10th grade for any more official instruction. That year I learned Pascal. In my junior year, my computers teach got me an after-school job with a local engineering firm. They were looking for someone to build and maintain some applications for them. I interviewed and got the job. I still remember my first day – sitting down at the leased 286 with an orange monochrome screen. My boss dropped off a big box of discs and manuals for something called Ashton Tate dBase IV. He then said he wanted me to build them a database for all of their pumps and related devices. After looking through the manuals the rest of the day, I stopped in to my boss's office to let him know that I thought I might be in over my head. "Nonsense", he told me. "Why don't you take a few weeks to read the manuals and play around with the software, and if you still feel the same way, then I'll understand and we can part ways with no hard feelings." Turns out dBase wasn't so hard to work with after all. That job lasted me the rest of my time in high school and provided a lot of great programming experience as I built and maintained several networked client-server applications for the company.

As much as I enjoyed computers, I still couldn't see making a living working with them. I had considered doing a degree in computer science, but everyone I knew who had gone that route hated it (granted most of my friends were only a year or two older than I was, so most of them were still working through the fundamental classes). I had this idea of writing snippets of large programs as part of a team of people with little satisfaction. I'm not sure exactly where I got this idea from, but it's something that I just wasn't interested in doing. Computers were always fun for me and I just couldn't bear the idea of taking all the passion out of something I loved by making it into a full-time job for the rest of my life. So instead of computer science, I forgot all about computers for a few years and pursued a double major in political science and sociology. I also enlisted in the Air National Guard as a means to pay my way through school.

Toward the end of my time at the University of Delaware (around 1993) I saw my first web page. I was instantly hooked. From there I started spending more and more time online and eventually started a small consulting company with two other guys I knew. Our main focus was web design and development for nonprofits. Looking back, we were way too early for the market we were primarily targeting. Most of the nonprofits we talked to were just learning about the web and had no idea how to really take advantage of it, let alone a budget to work with. Luckily we had a few small business clients that kept things going and allowed me to develop my skills. I was also working construction at the time to make ends meet.

By 1996 it was clear that the consulting company wasn't going anywhere. My two partners had full time jobs and families and the business just wasn't a high enough priority for them. My girlfriend at the time (now my wife), seeing that this was the case finally told me "you need to find a real job." I started looking in the newspaper the next day and found several promising leads for companies looking for someone to work on the web. After several interviews I happened on an ad for a small electronics company in West Chester, PA looking for a Webmaster to build and manage their corporate web site and intranet. I applied, had an interview, and was hired shortly after. This was early 1996.

I got to work immediately building out their website and intranet with a combination of static HTML and Perl for handling basic tasks like emailing form content. This worked well for a while, but it was only a matter of time before I was asked to add some dynamic content--the request was to "web enable" our corporate address book, which was stored in a Microsoft Access database. My first reaction was to develop the application in Perl. However, at the time, building an application like this in NT Perl (all of our web servers were NT based) wasn't feasible, so I began looking for other solutions.

I first tried a product called DB Web, from a company named Aspect Software that had just been acquired by Microsoft. After a bit of experimentation, I realized that DB Web wasn't what I was looking for. It was more of a tool for querying data from Microsoft Access databases (it wrote VB code on the back end) than a real application development platform. (As a side note, Microsoft stopped supporting DB Web shortly after I evaluated it and rereleased it as ASP (Active Server Pages) a few months later.)

Frustrated, I decided to look into another product I had been hearing about on a web development discussion list. The product was Allaire's ColdFusion (Cold Fusion at the time), a rapid application development platform for creating and deploying dynamic server-based web applications. Within hours of downloading the trial version of the software, I had created a proof-of-concept for the corporate address book application.

Fast forward 15 years and it's almost funny to imagine that I fell in love with a programming language that had just over 30 tags and functions in the 1.5 release. At the time, though, ColdFusion had enough power to handle any web programming task thrown my way. And as the tasks have become more complex, ColdFusion has kept pace. Although I no longer develop as part of my day-to-day responsibilities, I'm still heavily involved with ColdFusion and the ColdFusion community and I can honestly say that with each new release, ColdFusion contains features and functionality that seem to show up just as I find myself needing or wanting them.

Beyond what I think of ColdFusion as a technology, though, is what ColdFusion has provided me personally. Not only has it enabled me to earn a living, it's also been the catalyst for a lot of personal growth. Because of ColdFusion I have had the opportunity to write two books (on ColdFusion, of course), speak at countless user groups and conferences around the world, and literally meet hundreds of passionate, smart people who share my love of technology. Thanks ColdFusion!

User Defined Caches in Coldfusion 9.0 and 9.0.1

The follow up discussion to a recent blog post by Ray Camden made me realize that there's a lot of misunderstanding (including the ColdFusion documentation) about how ColdFusion's user defined caches work. In this blog post, I hope to clear up some of that confusion.

ColdFusion 9.0 completely overhauled CF's caching mechanism and replaced the old file based system with Ehcache. Out of the box, ColdFusion made two default caches available to every ColdFusion application, an object cache and a template cache. It was also possible to create additional user-defined caches at runtime, but only if you were using the cfcache tag, not the caching functions. Here's an example that puts and gets data from a user defined cache:

view plain print about
1<!--- attempt to get the artist query from the custom object cache --->
2<cfcache
3 key="myCustomObjectCache"
4 action="get"
5 id="artistQuery"
6 name="getArtists"
7 metadata="myMeta">

8
9<!--- if the item isn't there, it'll return null. In that case, run the query
10 and cache the results and rerun the data from the db instead --->

11<cfif isNull(getArtists)>
12 <cfquery name="getArtists" datasource="cfartgallery">
13 SELECT *
14 from artists
15 </cfquery>
16
17 <cfcache
18 key="myCustomObjectCache"
19 action="put"
20 id="artistQuery"
21 value="#getArtists#">

22</cfif>
23
24<!--- dump the query from cache --->
25<cfdump var="#getArtists#">

ColdFusion 9.0.1 added the ability to use user defined caches in many of the caching functions as well. Here's our previous example written using cacheGet() and cachePut() instead of the cfcache tag:

view plain print about
1<!--- attempt to get the artist query from the custom object cache --->
2<cfset getArtists = cacheGet('artistQuery', 'myCustomObjectCache')>
3
4<!--- if the item isn't there, it'll return null. In that case, run the query
5 and cache the results and rerun the data from the db instead --->

6<cfif isNull(getArtists)>
7 <cfquery name="getArtists" datasource="cfartgallery">
8 SELECT *
9 from artists
10 </cfquery>
11
12    <cfset cachePut('artistQuery', '#getArtists#', 15, 15, 'myCustomObjectCache')>
13</cfif>
14
15<!--- dump the query from cache --->
16<cfdump var="#getArtists#">

One thing to note here is that neither cacheGetProperties() nor cacheSetProperties() can be used to configure the properties for a custom cache in ColdFusion 9.0 or 9.0.1. If you want the cache configuration to differ from ColdFusion's default cache configuration, you'll need to configure the cache in your ehcache.xml file:

view plain print about
1<cache
2 name="myCustomObjectCache"
3 maxElementsInMemory="10000"
4 eternal="false"
5 timeToIdleSeconds="86400"
6 timeToLiveSeconds="86400"
7 overflowToDisk="false"
8 diskSpoolBufferSizeMB="30"
9 maxElementsOnDisk="10000000"
10 diskPersistent="false"
11 diskExpiryThreadIntervalSeconds="3600"
12 memoryStoreEvictionPolicy="LRU"
13 clearOnFlush="true"
14/>

Obviously it's not always desirable or even possible (say in the case of a shared hosting environment) to hard code configuration settings in the ehcache.xml file. Besides that, anytime you make changes to the XML file you need to restart ColdFusion for them to take effect. While I hope that Adobe adds the ability to set properties for custom caches in a future release of ColdFusion, there is a solution you can take advantage of today in the form of a small UDF I wrote called cacheCreate().

The cacheCreate() UDF allows you to create a new user defined cache at runtime and pass in configuration options that ColdFusion currently requires you to set in your ehcache.xml file. It uses Java to call the underlying Ehcache API and do the heavy lifting for you. Here's the code (you can also get cacheCreate() at cflib.org:

view plain print about
1<cffunction name="cacheCreate" output="false" returntype="void"
2    hint="I create a new user defined cache region in Ehcache"
3    description="I create a new user defined cache region in Ehcache. This function
4             allows you to also configure the attributes for the custom cache,
5             something you would normally have to hard code in the ehcache.xml
6             file if you rely on ColdFusion'
s built in caching functions. I named
7             the function cacheCreate() and not cacheNew() in the hopes that a
8             future version of ColdFusion includes a cacheNew() function with
9             similar functionality.">
10
11    <!--- this is what's configurable as of Ehcache 2.0 (CF 9.0.1). Only required
12         argument is Name --->

13    <cfargument name="
name" type="string" required="true">
14    <cfargument name="
maxElementsInMemory" type="numeric" default="10000">
15    <cfargument name="
maxElementsOnDisk" type="numeric" default="10000000">
16    <cfargument name="
memoryStoreEvictionPolicy" type="string" default="LRU">
17    <cfargument name="
clearOnFlush" type="boolean" default="true">
18    <cfargument name="
eternal" type="boolean" default="false">
19    <cfargument name="
timeToIdleSeconds" type="numeric" default="86400">
20    <cfargument name="
timeToLiveSeconds" type="numeric" default="86400">
21    <cfargument name="
overflowToDisk" type="boolean" default="false">
22    <cfargument name="
diskPersistent" type="boolean" default="false">
23    <cfargument name="
diskSpoolBufferSizeMB" type="numeric" default="30">
24    <cfargument name="
diskAccessStripes" type="numeric" default="1">
25    <cfargument name="
diskExpiryThreadIntervalSeconds" type="numeric" default="120">
26    
27    <!--- We need to do this in java because ColdFusion's cacheGetSession() returns
28     the underlying object for an EXISTING cache, not the generic cache manager --->

29    <cfset local.cacheManager = createObject('java', 'net.sf.ehcache.CacheManager').getInstance()>

30
31    <!--- constructor takes cache name and max elements in memory --->
32    <cfset local.cacheConfig = createObject("java", "net.sf.ehcache.config.CacheConfiguration").init("#arguments.name#", #arguments.maxElementsInMemory#)>

33    <cfset local.cacheConfig.maxElementsOnDisk(#arguments.maxElementsOnDisk#)>

34    <cfset local.cacheConfig.memoryStoreEvictionPolicy("#arguments.memoryStoreEvictionPolicy#")>
35    <cfset local.cacheConfig.clearOnFlush(#arguments.clearOnFlush#)>
36    <cfset local.cacheConfig.eternal(#arguments.eternal#)>
37    <cfset local.cacheConfig.timeToIdleSeconds(#arguments.timeToIdleSeconds#)>
38    <cfset local.cacheConfig.timeToLiveSeconds(#arguments.timeToLiveSeconds#)>
39    <cfset local.cacheConfig.overflowToDisk(#arguments.overflowToDisk#)>
40    <cfset local.cacheConfig.diskPersistent(#arguments.diskPersistent#)>
41    <cfset local.cacheConfig.diskSpoolBufferSizeMB(#arguments.diskSpoolBufferSizeMB#)>
42    <cfset local.cacheConfig.diskAccessStripes(#arguments.diskAccessStripes#)>
43    <cfset local.cacheConfig.diskExpiryThreadIntervalSeconds(#arguments.diskExpiryThreadIntervalSeconds#)>
44
45    <cfset local.cache = createObject("java", "net.sf.ehcache.Cache").init(local.cacheConfig)>
46    <cfset local.cacheManager.addCache(local.cache)>
47</cffunction>

To create and configure a new user defined cache in your application, all you need to do is something like this:

view plain print about
1<!--- let's build a struct of arguments. It's much easier to pass this way --->
2<cfset myProps = structNew()>
3<cfset myProps.name = "myCustomCache">
4<cfset myProps.maxElementsInMemory = 10>
5<cfset myProps.maxElementsOnDisk = 10>
6<cfset myProps.memoryStoreEvictionPolicy = "FIFO">
7<cfset myProps.clearOnFlush = true>
8<cfset myProps.eternal = false>
9<cfset myProps.timeToIdleSeconds = 86400>
10<cfset myProps.timeToLiveSeconds = 86400>
11<cfset myProps.overflowToDisk = false>
12<cfset myProps.diskPersistent = true>
13<cfset myProps.diskSpoolBufferSizeMB = 30>
14<cfset myProps.diskAccessStripes = 1>
15<cfset myProps.diskExpiryThreadIntervalSeconds = 120>
16
17<!--- create the new custom cache region --->
18<cfset cacheCreate(argumentCollection=myProps)>
19
20<!--- prove that it's there the CF way --->
21<cfdump var="#cacheGetSession('myCustomCache', 'true').getCacheManager().getCacheNames()#">

While this won't work in all cases (say you want to cluster your cache or add in a Terracotta Server Array), it should get you thinking about other ways you can extend ColdFusion's ehcache implementation by utilizing some of the Ehcache Java API within CF.

Thoughts on the Software AG Acquisition of Terracotta

As you might have heard, Terracotta -- the makers of Ehcache, the Terracotta Server Array, Quartz Scheduler and Big Memory recently announced their intent to be acquired by German software company Software AG. If you're wondering who Software AG is, you're probably not alone. Until recently, Software AG was a relatively little known company in the US. Although they've been in business since the late 1960's, their main market had been Europe. That all changed in 2007 when they acquired WebMethods, one of the largest providers of integration systems and services. This more than doubled their North American customer base. They continued to fuel their rapid growth from their mainly through acquisition. After WebMethods came IDS Scheer in 2009, Data Foundations in 2010, and now Terracotta. Each of their acquisitions has succeeded in growing their customer base, and in most cases, their revenue as well.

So, why Terracotta when Software AG is known as a business process and SOA infrastructure company? The first reason is for the technology itself, mainly Ehcache, Terracotta, and Big Memory. Software AG has big plans for the cloud, and in-memory capability and scalability play a huge part in building out their PaaS infrastructure. There are other potential benefits as well. Open source Ehcache claims an install base of over 500,000 with a sizeable open source community to back it. Although Software AG has little experience in the open source market, they've committed to the Ehcache and Quartz communities going forward. There's also the opportunity to improve job scheduling within the existing WebMethods suite. If you've ever used their existing scheduler, you know that it leaves much to be desired.

The company I work for has been a Software AG customer for close to 7 years now. We started with their ESB (Crossvision Service Orchestrator) and Tamino XML database, upgraded to WebMethods Integration Server after the merger, and have added capabilities around Business Activity Monitoring and SOA Governance since then. All along the way, Software AG has worked closely with us to meet our often challenging requirements. I think in that respect, Terracotta customers are in good hands. I've also spent considerable time working with Ehcache and Terracotta over the past 3 years now – writing articles and blog posts about their caching technology as well as speaking at several conferences. Although I didn't see the acquisition coming, I think combining the passion and talent of the folks at Terracotta with the resources and track record of Software AG will be a win for everyone involved.

While that last statement might sound like rainbows and unicorns, there is one area where I hope Software AG can learn from Terracotta, and that's community. Having been involved with various technology communities over the years, I feel that the Software AG community could use some help. With the exception of a few sites, there's little evangelism that happens outside of Software AG branded properties. Sure there are official Software AG blogs, and Software AG forums, but what I don't see is a vibrant community outside of Software AG writing about and talking about their products. Contrast that with Terracotta, and especially the Ehcache community and you'll see exactly what I mean. Let's hope that Software AG makes the most of the community they're getting along with the technology.

Slides, Config and Code from my cf.objective() 2011 Presentation

Slides, config files and code for my cf.objective() 2011 presentation, "Undocumented and Off Script: ColdFusion & Ehcache" are now available. You can view the slides inline, or download the attached zip file which contains the presentation and all files/code from the presentations.

As always, if you have questions or want to discuss, leave a comment or hit me up on twitter at @styggiti.

Speaking at cf.Objective 2011: Undocumented and Off Script: ColdFusion & Ehcache

Headed to cf.Objective 2011 and want to learn more about caching in ColdFusion with Ehcache? Stop by my session Undocumented and Off Script: ColdFusion & Ehcache on Thursday, May 12th at 10:15 am. I'll cover a broad range of topics including upgrading the version of Ehcache that ships with ColdFusion, clustered caching, distributed caching, cache search, cache monitoring, developer tools, and much, much more.

I hope to see you there!

Building High Performance Applications with ColdFusion 9 and Ehcache 2.4 on DZone

My latest article on Building High Performance Applications with ColdFusion 9 and Ehcache 2.4 is out on DZone. In addition to covering basic caching concepts, the article also walks you through the process of updating the version of Ehcache that ships with Coldfusion from 2.0 to 2.4 as well as installing and configuring a Terracotta server for distributed caching.

A Little Friday IT Humor: It Happens to the Best of Us

Anyone who has ever presented at a conference will be able to appreciate this one. Right in the middle of my Adobe MAX presentation on Configuring and Maintaining Healthy ColdFusion Servers. Thanks to Brian R. Detweiler for the photo ;-)

Slides from my Adobe MAX 2010 Presentation: Configuring and Maintaining Healthy ColdFusion Servers

Here are the slides from my Adobe MAX 2010 conference session: Configuring and Maintaining Healthy ColdFusion Servers.

If you were in the session, there are about 6 or so slides we didn't make it to thanks to the BSOD I had mid-preso.

As always, if you have any questions, feel free to hit me up on Twitter (@styggiti) or via email at [rbils at amkor dot com].

Recording, Slides and Demo Code now Available from my ColdFusion/Ehcache Webinar

The Webex recording, Powerpoint slides and example code I used in last week's Boosting Performance and Scale for ColdFusion Applications with Ehcache webinar are now available. You can watch the recording here (note that registration is required):

Boosting Performance and Scale for ColdFusion Applications with Ehcach

Additionally, you can view the presentation slides:

Alternately, you can download the slides.

You can also download the sample code.

Please note that the examples created for blogCFC should only be considered a POC to demonstrate concepts and not production ready code.