Skip to content

Instantly share code, notes, and snippets.

@awayken
Last active December 20, 2015 00:09
Show Gist options
  • Save awayken/6039516 to your computer and use it in GitHub Desktop.
Save awayken/6039516 to your computer and use it in GitHub Desktop.
CFML Caching Templates
<cfset local.cacheKey = hash( cgi.http_host, 'sha1' ) & '_CHANGEME'>
<cfset local.cacheTimespan = createtimespan( 0, 0, 10, 0 )>
<cfset local.cacheHTML = "">
<cfcache action="get" id="#local.cacheKey#" name="local.cacheHTML">
<cfif isNull( local.cacheHTML )>
<cfsavecontent variable="local.cacheHTML">
<!--- CFML here --->
</cfsavecontent>
<cfcache action="put" id="#local.cacheKey#" value="#local.cacheHTML#" timespan="#local.cacheTimespan#">
</cfif>
<cfoutput>#local.cacheHTML#</cfoutput>
<cfset var cacheKey = hash( cgi.http_host, 'sha1' ) & '_CHANGEME'>
<cfset var cacheTimespan = createtimespan( 0, 0, 10, 0 )>
<cfset var cacheHTML = "">
<cfcache action="get" id="#cacheKey#" name="cacheHTML">
<cfif isNull( cacheHTML )>
<cfsavecontent variable="cacheHTML">
<!--- CFML here --->
</cfsavecontent>
<cfcache action="put" id="#cacheKey#" value="#cacheHTML#" timespan="#cacheTimespan#">
</cfif>
<cfoutput>#cacheHTML#</cfoutput>
<cfscript>
local.cacheKey = hash( cgi.http_host, 'sha1' ) & '_CHANGEME';
local.cacheTimespan = createtimespan( 0, 0, 10, 0 );
local.cacheObject = cacheGet( local.cacheKey );
if( isNull( local.cacheObject ) ) {
// CFML here which creates local.cacheObject
cachePut( local.cacheKey, local.cacheObject, local.cacheTimespan );
}
</cfscript>
<cfscript>
var cacheKey = hash( cgi.http_host, 'sha1' ) & '_CHANGEME';
var cacheTimespan = createtimespan( 0, 0, 10, 0 );
var cacheObject = cacheGet( cacheKey );
if( isNull( cacheObject ) ) {
// CFML here which creates cacheObject
cachePut( cacheKey, cacheObject, cacheTimespan );
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment