eTag()
eTags are cool - read more about them here - eTags.
eTag() is a handy function that you can use to perform client-side programmable caching of your coldfusion pages.
To get the benefit just call <cfset eTag( "My Page" )> and the next time a user visits this page, they will get a 403 not modified response and execution will stop here.
Getting advanced... add in the date..
<cfset eTag( "#pageName#_#lastUpdatedDate#" )>
... this will regenerate the page IF the lastUpdatedDate has changed.
We use this extensively in Teamwork Project Manager to reserve dynamic pages almost instantly. It also reduces server load because processing stops.
Here is the code:
<!--- eTag will return a 304 not modified response if possible --->
<cffunction name="eTag" output="no">
<cfargument name="eTag" type="string" required="yes">
<cfargument name="useHash" type="boolean" required="no" default="yes">
<cfif useHash>
<cfset ARGUMENTS.eTag = Hash( ARGUMENTS.eTag )>
</cfif>
<cfheader name="ETag" value="""#ARGUMENTS.eTag#""">
<cfif ( StructKeyExists( CGI, 'HTTP_IF_NONE_MATCH' ) and CGI.HTTP_IF_NONE_MATCH contains ARGUMENTS.eTag )>
<cfcontent reset="yes">
<!--- nothing has changed, return nothing --->
<cfheader statuscode="304" statustext="Not Modified">
<cfabort>
</cfif>
</cffunction>
eTag() is a handy function that you can use to perform client-side programmable caching of your coldfusion pages.
To get the benefit just call <cfset eTag( "My Page" )> and the next time a user visits this page, they will get a 403 not modified response and execution will stop here.
Getting advanced... add in the date..
<cfset eTag( "#pageName#_#lastUpdatedDate#" )>
... this will regenerate the page IF the lastUpdatedDate has changed.
We use this extensively in Teamwork Project Manager to reserve dynamic pages almost instantly. It also reduces server load because processing stops.
Here is the code:
<!--- eTag will return a 304 not modified response if possible --->
<cffunction name="eTag" output="no">
<cfargument name="eTag" type="string" required="yes">
<cfargument name="useHash" type="boolean" required="no" default="yes">
<cfif useHash>
<cfset ARGUMENTS.eTag = Hash( ARGUMENTS.eTag )>
</cfif>
<cfheader name="ETag" value="""#ARGUMENTS.eTag#""">
<cfif ( StructKeyExists( CGI, 'HTTP_IF_NONE_MATCH' ) and CGI.HTTP_IF_NONE_MATCH contains ARGUMENTS.eTag )>
<cfcontent reset="yes">
<!--- nothing has changed, return nothing --->
<cfheader statuscode="304" statustext="Not Modified">
<cfabort>
</cfif>
</cffunction>
Peter Coppinger aka Topper is a neurotic web monster who spends most of his chaotic life developing ColdFusion web applications when not drinking himself into a stupor and scheming his plans for world dominance.