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?
Archived Comments
"request a file or folder to be clearer." ... er... to be cleared? :)
Doh. Fixed.
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.
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?
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.
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.
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%.
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.
I remember Contribute - it wasn't bad for what it did.
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.
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*.
OK so I turned it on. One word: rapid.
Good tip, can't believe I hadn't looked at it before!
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?
Thanks
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.
David - gotcha...thanks!
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.
Take a look at my Cache Clearer project. It uses the Admin API. You can too (well, as long as you have CF ENT).
yup...got that. Thanks, Ill check it out.
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!
*bows*..fantastic one jedi! thanks
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.
Thanks,
-Aaron
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.
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.
@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.
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.
@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.)
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?
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.
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.
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.
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.
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?
Cheers
Matthew
I've seen it not give a good boost, but I've never seen it slow down.
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.
Ray,
Do we have any option to clear Trusted cache in CF MX(6.1)?
Thanks in advance.
I honestly have no idea. It may require a server restart (CF service I mean, not the complete box).
@Ray,
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.
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.
Or is this something that is loaded to memory? And then I'm looking in completely the wrong spot.
Thanks, Ray! I'll check that out.
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?
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.
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.
The files aren't stored in cache. Instead, CF doesn't look at the CFM to see if it needs to be recompiled.
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.
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.
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.