刷新单个缓存的页面片段

时间:2011-11-25 11:48:44

标签: coldfusion cfcache

我不确定这是否可行..

我正在动态生成表格行,并希望将每一行缓存为页面拼写...例如

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

然后在其他代码中,在Applicaiton的一个完全不同的部分,我希望能够刷新单个片段..例如,如果我想要刷新'tableRow_2'..

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

任何人都可以告诉我这种粒度是否可行,如果是这样,最好的方法是什么。

我能找到的最接近的是<cflush expireURL="..">,但这会刷新页面中的所有缓存..我需要能够刷新页面中的各个缓存。

非常感谢提前!

杰森

2 个答案:

答案 0 :(得分:1)

您可以通过应用程序范围缓存池来处理此问题。例如:

<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>

然后,在应用程序的其他位置,您可以使用StructDelete:

StructDelete(application.cachePool, "tableRow_3")

答案 1 :(得分:0)

如果您使用CF9,则cfcache标记具有“id”属性。所以你可以准确地说出你的例子中的内容:

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

相关问题