03/01/2003: How Do I Prevent a Page From Caching in the Browser Using ColdFusion?
How Do I Prevent a Page From Caching in the Browser Using ColdFusion?
The following code should work in most situations. This code is courtesy of Cameron Childress).
<!--- Anti-cache ---> <CFSET gmts = gettimezoneinfo()> <CFSET gmt = gmts.utcHourOffset> <CFIF gmt EQ 0> <CFSET gmt = ""> <CFELSEIF gmt GT 0> <CFSET gmt = "+" & gmt > </CFIF> <CFHEADER NAME="Expires" VALUE="Mon, 06 Jan 1990 00:00:01 GMT"> <CFHEADER NAME="Pragma" VALUE="no-cache"> <CFHEADER NAME="cache-control" VALUE="no-cache, must-revalidate"> <CFHEADER NAME="Last-Modified" VALUE="#dateformat(now(), 'ddd, dd mmm yyyy')# #timeformat(now(), 'HH:mm:ss')# GMT#gmt#">
03/01/2003: How Do I Clear a CachedWithin Query Using ColdFusion?
How Do I Clear a CachedWithin Query Using ColdFusion?
If you use a dynamic timespan instead of a fixed timespan, you can clear the cache by setting the timespan to zero when the query is executed.
<cfif url.clear_cache eq 1> <cfset time_span = CreateTimeSpan(0,0,0,0)> <cfelse> <cfset time_span = CreateTimeSpan(0,0,30,0)> </cfif> <cfquery ... cachedwithin="#time_span#"> ... do some sql here. </cfquery>