DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. Programmatically clearing ColdFusion's Trusted Cache By Time

Programmatically clearing ColdFusion's Trusted Cache By Time

Raymond Camden user avatar by
Raymond Camden
·
Mar. 07, 13 · Interview
Like (0)
Save
Tweet
Share
3.72K Views

Join the DZone community and get the full member experience.

Join For Free

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.

<cfset files = directoryList(expandPath("../"),true,"query","*.cfc|*.cfm")>
<cfset toClear = []>
<cfset numhours = 1>
<cfloop query="files">
  <cfif dateDiff("h", datelastmodified, now()) lte numhours>
  	<cfset arrayAppend(toClear, directory & "/" & name)>
	</cfif>
</cfloop>

<cfinvoke component="cfide.adminapi.administrator" method="login" adminPassword="foo">
<cfinvoke component="cfide.adminapi.runtime" method="clearTrustedCache" templateList="#arrayToList(toClear)#">

<cfoutput>Done clearing cache. Cleared #arrayLen(toClear)# items.</cfoutput>
<cfdump var="#toClear#" label="Cleared Items">

Note - both the docs for cfdirectory and directoryList incorrectly state that only 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.)

Cache (computing)

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Apache Kafka vs. Memphis.dev
  • Pair Testing in Software Development
  • Tech Layoffs [Comic]
  • Core Machine Learning Metrics

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: