Twitter: raymondcamden


Address: Lafayette, LA, USA

Programmatically clearing ColdFusion's Trusted Cache By Time

03-06-2013 4,713 views ColdFusion Comments

I've blogged before about ColdFusion and trusted cache, with multiple entries on how you can clear that cache when updating files.

In ColdFusion 10, you can now clear a directory from within the CF Admin. For more fine grain control and older versions of ColdFusion, you can use my Admin extension, cacheClearer.

While these options work nicely, I needed something for my blog that skipped the administrator (which I've locked down on this server) and was quicker to use. Yes, even quicker then entering a folder in one form field.

I wrote up the following simple script that takes a base directory and gets all the files recursively. It then checks each file and sees when it was last updated. If it is within some threshold (for now, one hour), it adds it to a list that is then passed to the admin api.

Note - both the docs for cfdirectory and directoryList incorrectly state that one filter can be applied. As you can see in the script above that is not the case. You can pass multiple filters by delimiting them with a pipe character.

I added this to my blog admin so I can clear my cache with one button click. Hope this helps. (By the way, if one hour finds too many files, you can easily tweak the dateDiff to be minute based.)

0 Comments

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty