Posted in ColdFusion | Posted on 06-19-2008 | 8,551 views
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:
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.



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?
By the way, the image does not work.
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.
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?
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.
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.
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.
@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.
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.
There are several dozen small (and some important) changes beyond the big things you hear talked about all the time.
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?
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."
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>
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.
I did file an enhancement request for this with Adobe (like 2 mins ago).
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.
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
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?
By the way where is the Admin API documented?
Thanks,
Eric P
Ps. the lucky captcha I got to type was 'die'. (*shiver*)
I'll update the link in my guide soon.
http://cacheclearer.riaforge.org
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
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/questions/1429368/element...
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 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?
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?
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.
[Add Comment] [Subscribe to Comments]