1

Im not sure if this is possible..

I am dynamically generating table rows, and want to cache each row as a page fragement.. such as

<cfloop index="i" from="1" to="10">
    <cfcache id="tableRow_#i#">
        <tr><td>..some stuff..</td></tr>
    </cfcache>
</cfloop>

Then in other code, in a completely different part of the Applicaiton, I want to be able to flush individual fragments.. for example, if I want to flush 'tableRow_2'..

<cfcache action="flush" id="tableRow_3">

Can anyone tell me if this type of granularity is possible, and if so what the best approach would be.

The closest I have been able to find is <cflush expireURL="..">, but this flushes all caches in the page.. where I need to be able to flush individual caches in a page.

Many thanks in advance!

Jason

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Jason
  • 1,957
  • 2
  • 20
  • 34

2 Answers2

1

One way you could handle this is via an application-scope cache pool. For example:

<cfif not IsDefined("application.cachePool")>
  <cfset application.cachePool = {}>
</cfif>

<cfloop index="i" from="1" to="10">
    <!---<cfcache id="tableRow_#i#">--->
    <cfif not StructKeyExists(application.cachePool, "tableRow_#i#")>
        <cfsavecontent variable="cacheTmp"><tr><td>..some stuff..</td></tr></cfsavecontent>
        <cfset application.cachePool["tableRow_#i#"] = cacheTmp>
    </cfif>
    #application.cachePool["tableRow_#i#"]#
    <!---</cfcache>--->
</cfloop>

Then later on, elsewhere in the app, you can use StructDelete:

StructDelete(application.cachePool, "tableRow_3")
Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
0

If you're using CF9 the cfcache tag has an "id" attribute. So you can say exactly what you had in your example:

<cfcache action="flush" id="tableRow_3">

hofo
  • 522
  • 1
  • 4
  • 16
  • Hi hofo, thanks for your addition.. I am using cf9. I thought I would be able to do this as well, and I did try this, but was getting an error. I'll have a play next time I am in there and post the error.. – Jason Dec 01 '11 at 22:04