yes Bert, thats all very well, but if you're caching _whole_ templates, with
htm and data, then it may be fast, but as you point out, any variation in
the display (eg setting bgcolor = client.favcolor) is not an option.
A better approach might be to cache the data only, ie use cffile to write a
file containing a large cfscript block, which builds a structure (of
structures and arrays etc etc).
Then cfinclude this file, and use the structure it generates in a display
templete.
When the data changes delete the cached file.
<cfparam default="bar" name="url.foo">
<cfset cachename = url.foo & ".cfm">
<cfset thisdir = GetDirectoryFromPath(ExpandPath("*.*"))>
<cfset cachedfile = thisdir & cachename>
<!--- if the file doesn't exist then create it --->
<cfif Not FileExists(cachedfile)>
<!--- build the tmp variable as a cfscript block --->
<cfset tmp = "<cfscript>">
<cfset tmp = tmp & "mystruct = StructNew();">
<cfset tmp = tmp & "mystruct.file = """ & cachename & """;">
<cfset tmp = tmp & "mystruct.time = """ & now() & """;">
<cfset tmp = tmp & "</cfscript>">
<!--- and write the cfscript block as a file --->
<cffile action="Write"
file="#cachedfile#"
output="#tmp#"
addnewline="No">
</cfif>
<cfinclude template="#cachename#">
<cfoutput>
<b>#mystruct.file#</b> was cached at <b>#mystruct.time#</b>
</cfoutput>
Using this method, then you're only caching the data, but the display is
still dynamic.
Bert
> -----Original Message-----
> From: Bert Dawson [mailto:[EMAIL PROTECTED]]
> Sent: 26 March 2001 19:45
> To: Fusebox
> Subject: caching generated
>
>
> I've been doing a bit of fiddling around with caching stuff,
> and come up
> with this for a custom tag that can be wrapped around the cfswitch:
>
>
> <!---**** start of cunning_cacher ****--->
> <!--- this could be sorted out in formURL2attributes (if it
> survives...)
> --->
> <CFSET cachefile = ListChangeDelims(request.attributeslist,"+", "&")>
> <CFSET cachefile = ListChangeDelims(cachefile,"+", "=")>
> <CFSET cachefile = cachefile & ".htm">
>
> <CFIF ThisTag.ExecutionMode IS "start">
> <CFIF FileExists("d:\www\cachetest\#cachefile#")>
> <CFINCLUDE TEMPLATE="cachetest/#cachefile#">
> <CFEXIT METHOD="EXITTAG">
> </CFIF>
> <CFELSE>
> <CFFILE ACTION="WRITE"
> FILE="d:\www\cachetest\#cachefile#"
> OUTPUT="#ThisTag.generatedContent#">
> <CFINCLUDE TEMPLATE="cachetest/#cachefile#">
> <CFSET ThisTag.GeneratedContent = "">
> </CFIF>
> <!---**** // end of cunning_cacher ****--->
>
> Apart from the obvious chore of deleting cached files when the dB is
> updated, does anyone have any comments, see any drawbacks/problems?
> Cheers
> Bert
>
> ps Oh yeah, and it wouldn't work too well if you're using any kind of
> client/session management...
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists