Why aren't you using Trusted Cache?

This post is more than 2 years old.

Last night I was honored to give a presentation to the Capital Area CFUG. My presentation was a preview of my MAX topic, "Best Practices of the Modern CF Developer." During the presentation the topic of Trusted Cache came up and I was truly surprised to hear that next to no one was using this in production.

While certainly not a silver bullet for performance issues, turning on the Trusted Cache (see screen shot below) can sometimes dramatically increase the performance of your site in the one second it takes for you to check a box. That's a huge win for little to no work on your part.

Seriously - go to your production site, hit that box, and tell me if you don't see your site running significantly faster afterwards. There is no XML involved. No Server restart. Just a checkbox.

Now - there is one small drawback. After you've done this, ColdFusion will no longer look at your CFML pages for changes. In order to tell ColdFusion to check a file again, you either have to a) hit the button below:

or b) make use of CacheClearer, a ColdFusion Admin extension that let's you specifically request a file or folder to be cleared.

So... why aren't more of you using this?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Todd Rafferty posted on 10/13/2010 at 4:37 PM

"request a file or folder to be clearer." ... er... to be cleared? :)

Comment 2 by Raymond Camden posted on 10/13/2010 at 4:38 PM

Doh. Fixed.

Comment 3 by Grant Eagon posted on 10/13/2010 at 5:03 PM

Ha! My code's terrible performance forced me to turn this on years ago and I always use it! :)

Seriously though, I think there's a big difference in the experience developers gain when they run an app across multiple domains, that developers whose experience is primarily with single domain or intranet apps lack.

I have been working with one of those "website builder" sites for years, which seemed to exponentially stress my server with traffic from search engines. If you had one bad query running in your app, you had hundreds of bad queries running on the site, and hundreds of thousands of bad queries running on your live sites.

This forced me to get better at Apache configs, SQL and code performance because the server would go down under load.

Comment 4 by Louis posted on 10/13/2010 at 5:19 PM

Sorry if this is a stupid question, but I have to be sure before turning this option on.

I'm assuming that it is only the template that is cached. As in, the database/directory queries or, say, http requests etc contained within a template are not cached unless this is specified in the query tag? We have live stock levels on our website and obviously I would not want those to be cached along with the template?

Comment 5 by Raymond Camden posted on 10/13/2010 at 5:25 PM

Not a stupid question. So yes - just your CF code is cached, not the actual results. So as a simple example, if you had #randRange(1,10)# in the CFM, you would still get random numbers output. Caching of the _results_ is another topic.

Comment 6 by Louis posted on 10/13/2010 at 5:38 PM

Fantastic. We run a reasonably busy e-commerce site which uses live stock levels from SQL Server. Common sense would say that of course queries etc aren't cached, that would be counter-productive, but I had to be sure and couldn't find a definitive answer on Google! :)

Thanks for your help, Ray.

Comment 7 by David R. McGraw posted on 10/13/2010 at 5:51 PM

After reading this I decided to see what Railo offers in the form of the same setting. Railo has 3 settings, Check Always, Check Once, and Check Never. My setting was set to check once for www.oyova.com and although I thought that would be good, I went ahead and set it to never, ( the equivalent of the setting noted above ) and it increased the speed by at least 50%.

Comment 8 by Sean Coyne posted on 10/13/2010 at 5:52 PM

We didn't use it at my old job because we had a lot of older sites where the staff used Contribute to edit it. This is basically a glorified WYSIWYG FTP client and they would make changes and they wouldn't be displayed.

I tried adding a directory watcher event gateway, but the results weren't great.

Comment 9 by Raymond Camden posted on 10/13/2010 at 5:57 PM

I remember Contribute - it wasn't bad for what it did.

Comment 10 by Eddie posted on 10/13/2010 at 6:00 PM

We use it, we have to, otherwise all the years of crappy code would crush out servers. Unfortunately, we've always talked about automatically flushing, but the PHB's haven't made it a priority. So each dev must login to each server and flush cache. Absolute waste of resources.

Comment 11 by Grant Eagon posted on 10/13/2010 at 6:04 PM

We used to do the same thing. Then I started doing all my dev on my local machine and versioning the software. HUGE improvement. I don't know why more people don't do *that*.

Comment 12 by Louis posted on 10/13/2010 at 6:09 PM

OK so I turned it on. One word: rapid.

Good tip, can't believe I hadn't looked at it before!

Comment 13 by MB posted on 10/13/2010 at 6:10 PM

So, for instance, we are changing the code on our site on a regular basis to meet the users needs. Will we have to clear the cache in the CF admin in order to reflect these changes?

Comment 14 by David R. McGraw posted on 10/13/2010 at 6:11 PM

MB, just work in the process to your release schedule. Every time you make a release, part of the process will be to flush the cache.

Comment 15 by MB posted on 10/13/2010 at 6:13 PM

David - gotcha...thanks!

Comment 16 by MB posted on 10/13/2010 at 6:15 PM

sorry one other thing. Is there a way to programatically flush this cache without going into the CF admin? We have a couple of programmers and we dont want to have to have them log in and do this everytime. I would rather add something into our admin site to handle this.

Comment 17 by Raymond Camden posted on 10/13/2010 at 6:17 PM

Take a look at my Cache Clearer project. It uses the Admin API. You can too (well, as long as you have CF ENT).

Comment 18 by MB posted on 10/13/2010 at 6:21 PM

yup...got that. Thanks, Ill check it out.

Comment 19 by Tom Jenkins posted on 10/13/2010 at 6:32 PM

We tend to use this only on our servers that have a small, limited number of applications running on them (normally around 5 - 10).

We cache quite a lot of cfc's and their respective methods within the Application scope so it would mean on our larger servers, which have 90+ applicastions running on them, whenever we make one simple change to a file we have would have to clear the entire cache, which would then mean all of the cfc's need re-adding to Application scope. In testing, this meant sites would be very, very slow until everything had caught up and re cached.

... that is until I just read about CacheClearer! Which seems to fit and solve the above problem :D

Thanks Ray!

Comment 20 by cf wookie posted on 10/14/2010 at 12:09 AM

*bows*..fantastic one jedi! thanks

Comment 21 by Aaron Neff posted on 10/14/2010 at 12:53 AM

Hi Ray,

Just wanted to say, good post. Trusted Cache feature is very good, but I just felt it could be enhanced. I'd filed ER #74860, in case anyone is interested (no votes yet), here: http://cfbugs.adobe.com/cfb...

Basically, this ER is for allowing applications to enable/clear their own application-specific trusted cache. I just figured a THIS.enableAppTrustedCache for Application.cfc and a clearAppTrustedCache() function would be helpful.


Comment 22 by johans posted on 10/14/2010 at 1:07 AM

One thing to be aware of is if you app writes/cfincludes CF templates. If the template name does not change the output will not change, also you could quickly fill up the template cache.

Comment 23 by Patrick Heppler posted on 10/14/2010 at 2:10 AM

Nope, Site runs as fast as before. But that's fine, Site was always fast enough. There are many ways to get performance boost. MySQL Query Cache, Apache's mod_deflate etc.

Comment 24 by johans posted on 10/14/2010 at 2:18 AM

@Ray - so this got me thinking - how would you process CFML (that changes) inside a template?

Say I create an in-memory file ram:///mycfml.cfm and in a template use cfinclude to cause the CFML in mycfml.cfm to be run.

Trusted cache will output the template with the included content as cached the first time. Any changes in mycfml.cfm will never appear.

Comment 25 by Raymond Camden posted on 10/14/2010 at 3:57 PM

I'm pretty sure it would not pick up on it - but I've not done testing with CFMs in the VFS. Let me do a quick test later today to confirm.

Comment 26 by Raymond Camden posted on 10/14/2010 at 4:00 PM

@Aaron: Smart idea - I just voted for it. (Remember kids - anyone who likes something reported on the public bug tracker can vote for it to add their support.)

Comment 27 by Marcel posted on 10/14/2010 at 4:10 PM

We turned it on after reading about it, we didn't see any (major) improvements in speed. After a few hours we pressed the 'clear template cache' button to see what kind of impact it would have on the server, our server hing and we had to restart the ColdFusion instance (full queue in seefusion). We did press the button to see what the impact would be after a code update (yes I know, not really smart on a production server).

Is it normal that all requests will hang for (quite) some time?

Comment 28 by Raymond Camden posted on 10/14/2010 at 4:16 PM

I definitely see a big slow down after clearing it all, but not a permanent break - just a real slow next hit. Then again, I've also got a framework in place and I'm also clearing _that_ cache too. So your server should definitely not die just because you clear the cache. I'd look at other settings as well - perhaps your min/max JVM memory settings.

Of course, thats another reason I use CacheClearer - so I don't have to clear the entire cache.

Comment 29 by Marcel posted on 10/14/2010 at 4:23 PM

Thanks, the server is running fine normally (after our upgrade to 64bit due to memory issues before). The JVM settings are fine and tuned a while back by the makers of seefusion.

I think we were just a bit impatient and restarted CF too fast, waited about 40 secs till restart because the phone began to rang with the support desk members complaining about the application.

I'll do a better test in our staging enviroment and implement cacheclearer in our software to clear specific files that are changed at the update.

Comment 30 by Raymond Camden posted on 10/14/2010 at 8:20 PM

Ok, so for the guy who asked, the VFS is indeed impacted by trusted cache. Going to write a quick blog entry demonstrating this now.

Comment 31 by Raymond Camden posted on 10/14/2010 at 8:20 PM

Ok, so for the guy who asked, the VFS is indeed impacted by trusted cache. Going to write a quick blog entry demonstrating this now.

Comment 32 by Matthew posted on 11/5/2010 at 8:58 AM

Hi Ray. Just ran a quick trial and bizarrely it slowed things down. I ran my test by running a Paessler stress test before and after switching this feature on. It slowed all pages by about 100ms. I'll have to investigated because I only had a quick play. I'll report back but are there any scenarios where you could see a slow down happening and therefore not to use this feature i.e. perhaps if you use a framework?

Comment 33 by Raymond Camden posted on 11/5/2010 at 5:42 PM

I've seen it not give a good boost, but I've never seen it slow down.

Comment 34 by Daniel Godinez posted on 6/2/2011 at 3:23 AM

We've enabled trusted cache as our source code resides on a separate server from the CF8 instances. We instantly saw improvement in the load time of our pages. I have to admit though, on two occasions so far (out of 15), the coldfusion servers have hung during the clearing of the cache. The last time I executed it was during a low traffic period so I let it run and it did not come good till 102 secs, other times it executes immediately. This being the case, if you are taking advantage of clustering in coldfusion with session replication it sounds like it is far more beneficial to restart the instance instead of clearing the cache as it takes less time.

Comment 35 by Srinivas posted on 2/22/2012 at 8:59 PM


Do we have any option to clear Trusted cache in CF MX(6.1)?
Thanks in advance.

Comment 36 by Raymond Camden posted on 2/22/2012 at 9:04 PM

I honestly have no idea. It may require a server restart (CF service I mean, not the complete box).

Comment 37 by Gareth Arch posted on 3/14/2012 at 6:49 PM

Do you know where the trustedcache (and component cache) is located? We want to use our Ant script to clear it, but weren't sure where the files were located. I *thought* it was cfusion.ear\cfusion.war\WEB-INF\cfclasses but after clicking "clear template cache" and "clear component cache" all of the files that were in that directory still appear to be there.

Comment 38 by Raymond Camden posted on 3/14/2012 at 6:57 PM

I think it's RAM based - ie, it loads the compiled class in RAM. I believe - stress - believe - that Doug Hughes had a CF ANT task project and part of it would support clearing the cache via the Admin API. I'd google for that.

Comment 39 by Gareth Arch posted on 3/14/2012 at 7:00 PM

Or is this something that is loaded to memory? And then I'm looking in completely the wrong spot.

Comment 40 by Gareth Arch posted on 3/14/2012 at 7:01 PM

Thanks, Ray! I'll check that out.

Comment 41 by leeish posted on 12/10/2014 at 4:23 PM

Does anyone know what the impact of trusted cache is on the machines RAM? Where is this cache stored? Might I need to increase the RAM on my VM if I implement this?

Comment 42 (In reply to #41) by Raymond Camden posted on 12/10/2014 at 4:28 PM

Trusted Cache tells CF to *not* look at a files mod date to see if it needs to be recompiled. It should only need to store the path of files checked so RAM usage should be minimum (afaik) and *far* outweighed by the benefits.

Comment 43 (In reply to #42) by leeish posted on 12/10/2014 at 6:40 PM

I was thinking it stored those files in memory somewhere, thus using additional memory. From your answer, it sounds like CF always stores compiled versions of pages in memory, but with trusted cache just tells CF not to look at mod dates, so RAM usage wouldn't really increase as a whole. I'm using it on a server, and have been sometime, and I'm trying to narrow down some memory issues I'm having. Was curious how that actually worked.

Comment 44 (In reply to #43) by Raymond Camden posted on 12/10/2014 at 9:18 PM

The files aren't stored in cache. Instead, CF doesn't look at the CFM to see if it needs to be recompiled.

Comment 45 (In reply to #44) by leeish posted on 12/10/2014 at 9:46 PM

So pardon my ignorance. Where the hell does it get the information to display to send to the user? I get the not checking/recompiling, but the information has to be stored somewhere right? Taking up either RAM, VRAM, in the JRE memory or something right? If you don't feel like explaining and can point to a relevant article I understand.

Comment 46 (In reply to #45) by Raymond Camden posted on 12/10/2014 at 9:50 PM

ColdFusion takes your CFM file and compiles it into Java byte code that can then be run by the underlying Java engine. With Trusted Cached turned off, every day you request foo.cfm, ColdFusion looks at the file to see if it has been changed - like by you editing it. If it hasn't changed, it doesn't need to recompile it, right?

So with TC turned on, CF compiles the file once and *never* looks again. That's why you need to clear the TC (or clear the file from TC) if you make an edit.

Comment 47 (In reply to #46) by leeish posted on 12/10/2014 at 10:13 PM

Thanks for the explanation. Appreciate your blog and contributions to the community by the way. I would imagine a lot of us stand upon your and Ben's shoulders.