Posted At : Oct 07, 2007 22:52 PM
| Posted By : Ed Tabara
Related Categories:
ColdFusion,
CachingOk. Seems like i've got it working.
First i tried this
in Application.cfm and it helped. BUT as result the pages were loading over 2 seconds each time. and of course it was not acceptable
So, i went from Rob Wilkerson's idea of substituting a part of the cached version of the entire page with the needed part. But the problem is that theoretically it's not known what exactly and with what exactly should be changed (because of the dynamic nature of what should be changed and/or because i wanted to make it generalized enough).
So i had to find or have some kind of markers that will allow uniquily identify the needed parts of the source html. And this is not difficult. This way i came to the following process:
1. Inside the pod script, around the code that will be output on the blog, i place a tag that does not really exists. In order to make it simple, i decided to use as so the name given to the pod. So, the pod's script will look something like this:
....
here goes pod code
...
2. In Applicatiion.cfm, somewhere at the top but after the CFAPPLICATION tag do a CFINCLUDE of a file with the following code (i placed it right after udf.cfm's cfinclude):
", application.SCOPECACHE[application.applicationName].value, 1)>", application.SCOPECACHE[application.applicationName].value, 1)-1)>", application.SCOPECACHE[application.applicationName].value, 1)+Len(podElement)+2)>
So.. what do we have here..
First of all, in the
notCachedPodNamesvariable we set all the pod names for the pods that we don't want to be cached and
in notCachedPodFilesthe actual names of that pods. Then we do a loop for the number of elements in that lists and do the needed substitution. As can be seen, first the script look for the open tag of the current pod name (for example
) and save in
thisAppVar1the first part of the source. Then we delete from the top everything including the close tag for the current pod name (for example
). Now we save in the
thisAppVar2variable the execution of the current pod. And finally we replace the existing cache for the page html source (
application.SCOPECACHE[application.applicationName].value) with the concatenated values of
thisAppVar1,
thisAppVar2and the rest of
application.SCOPECACHE[application.applicationName].value.
All DONE. Now our cache contain the modified version of the html source. And it work FAST. For me, loading the blog with that process inside, rarely goes over 70 milliseconds.
Comments (2)|
Print|
Send
| 1325 Views
| 13% / 14% Popularity