我不确定这是否可能..
我正在动态生成表行,并希望将每一行作为页面碎片进行缓存。比如
<cfloop index="i" from="1" to="10">
<cfcache id="tableRow_#i#">
<tr><td>..some stuff..</td></tr>
</cfcache>
</cfloop>然后在其他代码中,在应用程序的完全不同的部分中,我希望能够刷新单个片段。例如,如果我想刷新'tableRow_2'..
<cfcache action="flush" id="tableRow_3">谁能告诉我这种类型的粒度是否可能,如果是的话,最好的方法是什么。
我所能找到的最接近的是<cflush expireURL="..">,但它会刷新页面中的所有缓存。其中我需要能够刷新页面中的单个缓存。
首先要感谢大家!
杰森
发布于 2011-11-26 01:33:10
处理这种情况的一种方法是通过应用程序范围的缓存池。例如:
<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")发布于 2011-11-29 05:38:17
如果您使用的是CF9,那么cfcache标记有一个"id“属性。因此,您可以准确地说出您在示例中所拥有的内容:
<cfcache action="flush" id="tableRow_3">
https://stackoverflow.com/questions/8268686
复制相似问题