Rob Brooks-Bilson
Tech, Photography, Stuff
Tech, Photography, Stuff
May 19, 2012
Thanks to everyone who came out to hear my presentation on Ten Steps to Move your Use of Caching Beyond the Basics at cf.Objective 2012. As promised, here are the slides, demo code, and ehcache.xml config file from the session.
Ten Steps to Move your Use of Caching Beyond the Basics (zip)
May 18, 2012
Below you'll find a link to the slides from my cf.Objective 2012 presentation on Maintaining Healthy ColdFusion Servers. Thanks to all those who came out to see the talk!
January 19, 2012
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.
June 22, 2011
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:
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:
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:
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:
To create and configure a new user defined cache in your application, all you need to do is something like this:
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.
May 13, 2011
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.
April 27, 2011
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!
April 26, 2011
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.
August 19, 2010
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.
August 9, 2010
I submitted a bug for this but the system seems to have swallowed it up without giving me the bug number (probably because I submitted as cf 9.0.1).
I've found what I consider to be a serious bug an issue with ColdFusion's
ehache implementation and query objects that may bite you if you're not aware of how it works. If I take a query object and stick it in cache, then perform an operation on the original query
object such as adding a column or performing certain query of query
operations, ColdFusion is treating the query object that's in cache as
if it were a copy by reference to the original query object. That is,
if I make a change to the original query object, ColdFusion is also
applying the change to the version that's in cache.
As far as I'm concerned, cache represents a boundary that ColdFusion
should not implicitly cross. With most caching systems I've worked with in the past (such as memcached), the cache always acted as a dumb key/value store. Unless I perform an explicit cachePut(), I wouldn't expect that CF would update values in the cache. Here's
two code snippets that reproduces the case. The first uses the
cfartgallery data source:
The second example shows how this can be done with a query of a query, based on a different bug Ray found previously (see http://www.coldfusionjedi.com/index.cfm/2009/8/28/Another-example-of-the-QofQ-Bug). In this sample, note that the date gets reformatted by the query of a query and both the original query and the cached version get updated:
The work around for this problem is to use the duplicate() function to make a clone of the query object before doing the cachePut(). Although this works, there are other potential consequences from having two copies of the query around, so be careful.
Update: It looks like this is actually expected behavior in Ehcache. Unfortunately, it's not documented in the ColdFusion documentation anywhere, but Ehcache actually has two configurable parameters (as of v. 2.10) called copyOnRead and copyOnWrite that determine whether values returned from the cache are by reference or copies of the original values. By default, items are returned by reference. Unfortunately we can't take advantage of these parameters right now as CF 9.0.1 implements Ehcache 2.0.
I can live with this, but it's not what I expected as I've always viewed Ehcache as a "dumb" key-value store and certainly didn't expect this behavior. Even if ColdFusion was running v 2.10 of Ehcache, it's still not something we could easily configure. Since ColdFusion currently doesn't have a cacheNew() function for creating new user-defined cache regions, the only way to turn this functionality off would be to hard-code your cache configuration in your ehcache.xml file for each user-defined region where you want to disable copyOnRead and copyOnWrite.
August 5, 2010
ColdFusion 9.0.1 added a new function called cacheGetSession() that returns the underlying cache object for Ehcache. What's really cool about this is that it allows you to get at just about all of the features available in Ehcache that aren't directly exposed to ColdFusion through built-in functions.
I was recently working on some example code for an upcoming caching presentation when I ran into a situation where I wanted to get a list of all caches that had been created on the server, including custom caches I had created myself. One simple line of code is all it took:
What you should note here is that even though I'm telling cacheGetSession() to get the cache object for the default object cache, getCacheManager() exposes a method called getCacheNames() which returns an array of cache names for the instance of cache manager. In the case of ColdFusion's Ehcache implementation, ColdFusion instantiates cacheManager as a singleton such that all caches are managed by the single cache manager. When you call getCacheNames(), it will return you a list of all caches currently implemented on the instance of ColdFusion.
While this may not be an issue for many people, if you are on a shared server it may be a concern. The only way to disable this is to disable the cacheGetSession() function using sandbox security.