【问题标题】:Flushing individual cached page fragments刷新单个缓存页面片段
【发布时间】:2013-12-06 11:54:50
【问题描述】:

我不确定这是否可能..

我是动态生成表格行,想把每一行缓存为一个页面片段..比如

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

谁能告诉我这种粒度是否可行,如果可行,最好的方法是什么。

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

提前非常感谢!

杰森

【问题讨论】:

    标签: coldfusion cfcache


    【解决方案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")
    

    【讨论】:

      【解决方案2】:

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

      &lt;cfcache action="flush" id="tableRow_3"&gt;

      【讨论】:

      • 嗨 hofo,感谢您的加入。我正在使用 cf9。我以为我也可以做到这一点,并且我确实尝试过,但是遇到了错误。下次我在那里玩并发布错误..
      猜你喜欢
      • 2015-08-05
      • 2017-05-24
      • 1970-01-01
      • 2011-05-11
      • 2011-09-24
      • 2016-07-02
      • 2014-12-29
      • 1970-01-01
      • 2012-08-13
      相关资源
      最近更新 更多