2011-11-25 100 views
1

林不知道这是可能的..冲洗个别缓存页面片段

我动态生成的表行,并希望缓存的每一行作为页面fragement ..如

<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="..">,但是这会刷新页面中的所有缓存......我需要能够刷新页面中的各个缓存。

非常感谢提前!

杰森

回答

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") 
+0

感谢Jake..worked请客.. – Jason

0

如果您使用的CF9标签cfcache有一个 “id” 属性。所以,你可以说,你在你的例子有什么:

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

+0

喜禾风,感谢您的加入..我用CF9。我以为我也可以做到这一点,我也尝试过,但发生错误。下次我在那里时我会有一个游戏,并发布错误.. – Jason