So, a while back, I wrote a CF_Accelerate-like tag (before I knew of
that one) and this one cached to file, memory, or cached query objects.
I think my locking is too aggressive, and is hurting performance. I
stripped down the tag below for readability...

Can you please advise me whether I can change this around in any way to
help performance?  (Downgrade any cflocks from exclusive to readonly?
Maybe eliminate some locking?)

Also, which of  CFFILE+Read vs. getPageContext.include()  is more costly
for outputting the cached file content?

For file-basedc caching, I write to [filename]_tmp, and then move it to
[filename] on the first read.  I was worried about clashes...

Any tips would be helpful... 

Thanks!


-----------------------------------

<Cfparam name="attributes.mode" default="File|Memory|Query">
<Cfparam name="attributes.key">
<Cfparam name="attributes.expires">
<Cfparam name="attributes.clearcache" default="false">
<cfparam name="application.contentcache" default="#Structnew()#">
<cfparam name="application.memorycachetagoutput"
default="#Structnew()#">
<cfparam name="application.mainquerycache" default="#Structnew()#">
<cfif thistag.executionmode is "Start">
        <cfif NOT attributes.clearcache 
                AND
structkeyexists(application.contentcache,attributes.key) 
                AND
abs(datediff('n',structfind(Application.contentcache,attributes.key),now
())) LT attributes.expires>
                <!--- CACHE HIT! --->
                <cflock timeout="15"  type="exclusive"
name="CacheTagOutput_#attributes.key#">
                <Cfif attributes.mode is "File">
                <cfif fileexists(filename &"_tmp")>
                        <Cfif fileexists(filename)><cffile
action="delete" file="#filename#" ></cfif>
                        <cffile action="rename" source="#filename#_tmp"
destination="#filename#">
                </cfif>
                        <!--- used to be CFFILE reading --->
                        <Cfset
getPageContext().include("#attributes.pagepath#partial_tag_cache/#attrib
utes.key#.cache")>
                <cfelseif attributes.mode is "memory">
        
<Cfoutput>#structfind(Application.memorycachetagoutput,attributes.key)#<
/cfoutput>
                <cfelseif attributes.mode is "query">
                        <Cfoutput><Cfset
"caller.#attributes.queryname#"=#structfind(Application.mainquerycache,a
ttributes.key)#></cfoutput>
                </cfif>
            <cfexit>
                </cflock>

        </cfif>
<cfelseif thistag.executionmode is "End">
                <!--- CACHE MISS (wouldn't have made it this far if a
hit) --->
                <!--- Insert Content --->
                <cflock  timeout="10" type="exclusive"
name="CacheTagOutput_#attributes.key#">
                <Cfif attributes.mode is "file">
                        <cffile action="WRITE" file="#filename#_tmp"
output="#thistag.generatedcontent#" addnewline="No">
                <cfelseif attributes.mode is "memory">
                        <cfset
structinsert(Application.memorycachetagoutput,attributes.key,"#thistag.g
eneratedcontent#",true)>
                <cfelseif attributes.mode is "query">
                        <Cfquery dbtype="query"
name="cachedQuery">select * From caller.#attributes.queryname#
</cfquery>
                        <cfset
structinsert(Application.mainquerycache,attributes.key,cachedQuery,true)
>
                </cfif>
        <!--- UPDATE TIMESTAMP OF KEY --->
        <cfset
structinsert(Application.cachetagoutput,attributes.key,now(),true)>
        </cflock>
        </cfif>


</cfif> 
--------------------------------------------------------
 
NOTICE: If received in error, please destroy and notify sender.  Sender does 
not waive confidentiality or privilege, and use is prohibited. 
 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Silver Sponsor - CFDynamics
http://www.cfdynamics.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188644
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to