A little bit ago I sat in the session "End to End Performance Tuning", which was a great session. One of the tips mentioned was the use of trusted cache on production systems. One of the problems with this though is that you need to clear the template cache for each and every little change. What folks tend to forget is that the Admin API has support to clear individual files. I blogged about this last year (at CFUN I think) and wrote up a quick little script to show an example of it. This came up again during the session so I thought I'd work a bit on the script and make it a bit more presentable in the ColdFusion Admin.
Take the script attached to this template and put it in your ColdFusion Administrator folder. Put it in a subfolder named anything you want, I used cacheclearer. Then edit custommenu.xml to add a link:
<menuitem href="cacheclearer/" target="content">Cache Clearer</menuitem>
Then hit up your Admin and you can run the utility. You can enter a CFM/CFC to clear or a folder and all CFM/CFCs under it will be clearer.
Archived Comments
Please identify the ColdFusion requirements as necessary.
This appears to be a CFMX 8-Only method. Can this be modified to work with CFMX 6 or 7? If so, is there any easy way to integrate it?
Right, this is CF8 only. As far as I know there is no way to do this with CF7.
Have there been any tests to determine the performance difference with trusted cache enabled/disabled?
By the way, the image does not work.
Thanks Ray, this is a nice solution to the problem. I've been using trusted cache for a couple of years now but found it annoying to clear it every time we have the most minor of code changes. An unsung feature of trusted cache is if you have code changes in multiple files across a few directories and you need to make all changes live at exactly the same time (because of file dependancies) then it's impossible without the use of trusted cache.
For the past month I've turned off trusted cache and haven't noticed any performance changes. I suspect it's only noticable if your server is running close to its limit, then it may shave a few milliseconds off each request - which adds up if you have lots of requests per second.
Casey - Adobe 100% recommends turning this feature on, and I know I've definitely seen improvements when doing it. Fixed the image.
Ray,
Is it possible to add a function to "onrequestend.cfm" to take a parameter (URL variable, IP address, browser agent, time window) and then determine which templates were recently used to generate the current page and clear them from the trusted cache?
If it is possible, would this method be advisable?
Adding a pointer to http://templatelistener.ria... for those that can use event gateways.
@Casey, there's clearly a performance benefit in that using trusted cache saves an i/o if a template can be found in the cache. CF then doesn't look to disk to test if the file has changed. When you know it will not, it's a good feature.
Of course, if the template cache is too small, then the value of having trusted cache enabled may be diminished, as the cache is thrashed removing requests and recompiling them.
Indeed, when Gary says he experienced no difference by enabling it, I'd wonder if that was the issue (unless it's simply that he didn't have enough requests on his server to notice any benefit from the i/o saved, which may be small per request but would increase in total value with more requests.)
@James, I don't understand what you're asking. What connection would you expect "recent use" to have on whether templates should be cleared from the cache? All that matters is whether the template has been *edited*, which is why tools that use the filewatcher gateway (as pointed to by Scott P) would be the way to go.
@Charlie, by recently used I meant all templates that were included or accessed in the page request.
For example if a simple template was updated, it would be nice to be able to pass a parameter or something and have an "onrequestend" function determine which templates were used in the generation of the page and delete them from the trusted cache. This would save a trip to the CFAdmin and requirement to find the templates that need to be deleted.
I looked at the solution offered by Scott P and the project states that ColdFusion 8 is a requirement... although I downloaded the project and the readme.txt has installation instructions for CFMX 6 & 7 but doesn't mention 8. I'm not sure if there a legitimate 8 requirement or whether it will it also work with 6/7.
I guess what frustrates me the most is reading an article and not knowing whether or not it will work on CFMX 7 because the writer takes it for granted that everyone is using 8. This has happened a couple of times in other forums and I find myself wasting time attempting to determine why something isn't working only to find that the developer uses new CF-8 only syntax or requires new hidden features not available in 7. I sometimes spend even more time trying to figure out a work-around to make it work. Sometimes I'm successful and other times I am not.
@James - clearing the cache will work on 7. The Difference between 7 & 8 is that in 8 you can clear a single or list of files from the cache instead of the whole cache.
If you are on 7 then you will be stuck with clearing the entire cache - the same as clicking on the clear template cache button in the admin. You could set the code to do that part for you.
@James - I guess that's my fault - not making it clear it was CF8 only. Although in my defense, the article I linked to clearly said it was cf8 only. :)
@Scott P - Thanks for the clarification. I currently have a method exposed in CFMX7 to clear the entire cache and was hoping to find a better way of doing it without having to resort to an upgrade.
@Ray - I read the linked article and thought that all the magic was in the Admin API and set of CFCs that may have also been possible to work with CFMX7. I didn't know if this was just a couple of new scripts that were added or if is an internal java update that allows it to do it. Is it possible that these CF8 CFCs would also work in CFMX7 but are available only in CF8?
Some organizations I work with remain on CF5 and CFMX6 due to budget constraints and the fact that "it's not broken" and "doesn't need updating." This requires me to integrate scripts that work across as many versions as possible to ensure that I can upsell new features to them as no new CF8 features that I've mentioned have enticed them to upgrade yet.
Ah, well, in that old article I do say: "Along with cool tags and functions added in ColdFusion 8, there have also been some neat updates to the Admin API." That's pretty clear I'd say. ;) But I shoulda been clear in this post as well. As far as I know you can't use the CF8 cfcs in CF7.
When I initially went through the new tag and function list, some CF8 features seemed like graduated CFTags and functions (that were already available) or internal wrappers for existing javascript libraries like FCKEditor and Ext (which are things I've been doing without the need for CF8.)
Don't get me wrong, I'm using CF8 too and I know that the upgrade is a lot more than just the inclusion of already existing third-party tags and libraries. I've been following many of the book, articles and blogs since CF2/3 and now more than ever I have to filter what I'm reading to determine which version (and potential client) I can actually apply these new tips too. I really don't recall having to do before as most tips seemed to be CFML-specific and not version or vendor specific.
James, if you need more ammunition for appreciation of what else has changed in CF8, check out my CF8 Hidden Gems presentation: http://carehart.org/present...
There are several dozen small (and some important) changes beyond the big things you hear talked about all the time.
Ray,
I downloaded and placed the code on my server. I just ran inot an issue where is does't actually remove any of the class files. If i put in an individual file it says that it is going to clear it. But it still exist in the directory. So i thought hmmm i will just do the entire direcotry. Well that didn't work either. For example: C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\cfclasses then select clear file/folder It doesn't throw an error it just doesn't do anything.
Ideas?
I think you misunderstand what this tool does. It does not delete the class files. When you turn on trusted cache, CF stops checking a CFM file to see if it has been updated and needs to be compiled again.
This utility doesn't clear the class files. Instead, it tells CF, "Hey, for these files, you need to check them on next execution to see if they need rebuilding."
Love this tool...thanks Ray...
I would suggest adding this line of code to the bottom of the page....It sets the "Last Page Visited" cookie like all the other admin pages.
<cfset cookie.CFADMIN_LASTPAGE_ADMIN = cgi.SCRIPT_NAME>
Yaron, thank you for this tip! This application here doesn't have a proper RIAForge project I think so folks tend to forget about it, but I may correct that. I'm also going to add this to SpoolMail. I also have a Verity tester CF Admin plugin.
Hey Ray, you mentioned in a comment here a couple of months ago that you might create a riaforge project from the cache clear/filewatcher combo. Did you ever get to? I didn't want to try to search fearing I may not use the right terms and figured folks would love to hear if you did.
Also, I would think this is a feature set that should be built into CF (or at least an admin interface to point to templates to clear manually). Have you made either suggestion as a feature request? It may be considered for Centaur, which would be awesome.
Nope, I did not make a RIAForge project out of it. Think its worth it?
I did file an enhancement request for this with Adobe (like 2 mins ago).
Well, I definitely think it's worth a project. Otherwise only those who find this entry and the other will know of it. It's just an awesome solution to an important problem (for those who recognize it, at least.)
Really great to hear you've requested it of Adobe. Of course, if it gets in then one could argue that the need of a project is diminished, but since 9 is still in the future, and even then many may remain on 8 who would benefit, it seems worth it, sure.
Alright, I'll look into it. I do see some benefit of just making it easier to find. Although I hope people are also using my CF Admin Extensions Guide: http://www.coldfusionjedi.c...
Hi, thanks a lot for this info. I've modified the extension a bit (to accept a list of files) and it's working great.
Is anyone aware of a way to check the state of the trusted cache toggle? I thought it'd be cool to deactivate the 'cache clearer' form when the trusted cache is toggled off.
Thanks again,
Eric P
I think supporting a list of files would be nice. I normally just enter a directory, but a list would be cool. Send me your mod.
You can tell if the trusted cache is on with the Admin API. It may be cool to add that to my tool as a flag. "Are you sure you want to clear cache? Trusted cache isn't even turned on, Bozo."
Shall I add that?
Sent via your Contact Me form.
By the way where is the Admin API documented?
Thanks,
Eric P
Ps. the lucky captcha I got to type was 'die'. (*shiver*)
In the developer's guide I believe - although not every single method. If you view the CFC in your browser, you can see a list of methods. (Don't forget you can open a CFC in your browser to see automatically generated documentation.)
Live: http://cacheclearer.riaforg...
I'll update the link in my guide soon.
Make that:
http://cacheclearer.riaforg...
I am using CFMX and there is an issue (variable "yy" is undefined in "yyfiling")thats a show stopper , on the production.
I am promoting corrections to it but they do not seem to show up on the server.
I want to resort to clearing the Server cache so that my promoted code can take effect.
The CFAdmin production template was cached (Trusted Cache turned on). so wanna turn it off Trusted Cache and clear template cache.
So was wondering it will effect the main site?
ANY PRECAUTIONS, as this is for a production server?
Thanks
-Vad
Does it really say yy in yyfling? That doesn't sound like my code. As it stands, I'm not sure if MX had the Admin API setting for this.
I am sorry to be out of context here, but i want to ask a general question.
Is what are the precautions to be mad if at all the server cache is to be cleared on CFMX admin?esp a production server.
I have the detailed issue i faced over here.
http://stackoverflow.com/qu...
If by server cache you mean the Server scope, then none. The cache clearing here just refers to the CFM cache.
Thanks a lot.
I meant in CFAdmin/cache/templated cache
I think the template was cached (Trusted Cache turned on),
So I want to turn off Trusted Cache and clear template cache.
As it is Live, wanted to know if any precautions?
The only real concern is that your next few hits will be a bit slow since has to re-cache stuff.
In this case....
The form fields were in saved session variables and then stored in a SAVED form.
My error was in opening the saved form.
I corrected it and pushed the code.
So was hitting on the last option as to turn off Trusted Cache and clear template cache.
Now would the SAVED forms with the old session-id be gone?
Thanks for this Ray.
I have my dev and live sites on the same box and would love to have the best of both worlds... trusted caching for the live site but non-cached templates on the dev. Do you have any ideas on how I could accomplish this without going to a dedicated dev server?
You can create an additional CF instance for dev and leave template caching off. (This only applies to a multi CF installation)
@Matt: Yaron answered, but let me just add - I strongly urge you not to run dev and production on the same physical box. Remember - ColdFusion is free for your dev server.
Hey Ray,
How can I make the CacheClearer custom menu option available in CFAdmin for my team without giving them full admin access? I've allowed them Console & API with the roles "Debugging & Logging > Logging" and "Server Settings > Settings Summary" but the custom menu generates a forbidden message when they attempt to run it.
Unfortunately, you can't. I'd just use the code _outside_ of the CF Administrator.
I'm trying to use it outside of my Administrator and it doesn't seem to be working.
I'd love to be able to add this to the root of my test sites so developers can flush when they need to without having Admin access.
Thanks!
Are the calls to the Admin API not working?