CFLib.org – Common Function Library Project

DeleteCFCache(cachedFile)

Last updated May 13, 2003

Version: 1 | Requires: ColdFusion MX | Library: UtilityLib

 
Rated 2 time(s). Average Rating: 1.0

Description:
Deletes a specified file from the Cold Fusion cfclasses cache directory, forcing ColdFusion to re-compile it. Returns true if successful, false if file was not found. Pass it your cf template's full or partial file name. This is especially great for servers with "Trusted Caching" turned on but you still need to make a change to a page, or for those mean servers that seem to keep files in cache even after updating them.

Return Values:
Returns a boolean.

Example:

view plain print about
<cfoutput>
<pre>
#DeleteCFCache("index.cfm")#
#DeleteCFCache("submit")#
#DeleteCFCache("bingobangobongo.cfm")# (always false)
</pre>
</cfoutput>

Parameters:

Name Description Required
cachedFile Filename, or partial filename. Yes

Full UDF Source:

view plain print about
<!---
 Force recompiling of a page in the cfclasses cached folder.
 
 @param cachedFile      Filename, or partial filename. (Required)
 @return Returns a boolean. 
 @author Nathan Strutz (mrnate@hotmail.com) 
 @version 1, May 13, 2003 
--->

<cffunction name="DeleteCFCache" output="false" returntype="boolean">
    <cfargument name="cachedFile" required="Yes" type="string">
    
    <cfset var qryDir = "">

    <!--- cfcache puts url encoding on files, lowercases them and removes percent signs --->
    <cfset arguments.cachedFile = URLEncodedFormat(arguments.cachedFile)>
    <cfif reFindNoCase("%2[A-Z]",arguments.cachedFile)>
        <cfset arguments.cachedFile = Replace(REReplace(arguments.cachedFile,"%2[A-Z]{1,1}",LCase(Mid(arguments.cachedFile,REFind("%2[A-Z]{1,1}",arguments.cachedFile),3)),"ALL"),"%","","ALL")>
    </cfif>
    
    <cfdirectory action="LIST" directory="#server.coldfusion.rootdir#\wwwroot\WEB-INF\cfclasses\" name="qryDir">
    <cfquery name="qryDir" dbtype="query">
        SELECT name
        FROM qryDir
        WHERE name like '%#arguments.cachedFile#%'
    </cfquery>
    <cfif not qryDir.recordcount>
        <cfreturn false>
    </cfif>
    <cfloop query="qryDir">
        <cffile action="DELETE" file="#server.coldfusion.rootdir#\wwwroot\WEB-INF\cfclasses\#qryDir.name#">
    </cfloop>
    <cfreturn true>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson