是否可以解析ColdFusion 9.0.1缓存内存的内容?

问题描述:

我从CF8到9的变化一直都是盲目的,在这种情况下,如果不创建自定义缓存或其他一些不值得花费的艰巨解决方法,写入磁盘缓存将不再可能。是否可以解析ColdFusion 9.0.1缓存内存的内容?

在这个时候,我已经放弃了尝试转换应用程序以支持,如果可能的话,将缓存文件内容写入静态cfm文件的方法。我现在更加好奇,因为我已经深入了解了它。我在找一个比我自己有更多经验的人。

我想什么,了解或知道如何与模板缓存做的是:

  1. 能够针对违约或自定义缓存模板,它不清除整个缓存刷新。
  2. 出于好奇或调试方法查看或解析特定缓存模板的内容。

这是我正在使用的代码,需要CF 9.0.1,由于一些缓存功能在9.0中不可用,这是因为我相信EhCache 2.0的增加。

<cftry> 
     <cfcache action='serverCache' timeout='#CreateTimeSpan(0,0,0,10)#' stripwhitespace='true' 
       usequerystring='true'> 
      Stuff to cache. 
      <br/> 
      <cfoutput>#now()#</cfoutput> 
      <br/> 
     </cfcache> 

     <!--- Get the cached contents ---> 
     <cfdump var="#cacheGetProperties()#"> 
     <cfdump var="#getAllTemplateCacheIds()#"> 
     <!---Locate a single cached item ---> 
     <cfscript> 
      cacheArray = getAllTemplateCacheIds(); 
      WriteOutput("Before<br/>"); 
      for(i=1;i LTE ArrayLen(cacheArray);i=i+1) 
      { 
       writeOutput(cacheArray[i] & "<br/>"); 
       if(FindNoCase(scriptPath, cacheArray[i])) 
       { 
        //expect only to find min and max one per string so no need to worry about out of bounds 
        cacheIDSubStr = REFind("[a-fA-F\d]{32}(?=_LINE:\d*$)",cacheArray[i],1,1); 
        cacheID = Mid(cacheArray[i],CacheIDSubStr.pos[1],CacheIDSubStr.len[1]); 
        //Failure to delete cache expected fireworks 
        //WriteOutput(cacheID&"<br/>"); 
        //cacheObject = CacheGet(cacheID); 
        //CacheRemove(cacheID); 
        templateCache = cacheGetSession("template"); 
         //Tooling around with the exposed guts of cacheGetSession 
        WriteDump(templateCache.getKeys()); 
       } 
      } 
     </cfscript> 
    <cfcatch type="Any"> 

     <cfscript> 
      writeoutput("Error:" & cfcatch.message); 
     </cfscript> 

    </cfcatch> 
    </cftry> 

没有错误应该存在,但它被编辑从原来在这里发布。

秘密是在CF 9.0.1功能cacheGetSession(),以及修改其他功能,以key作为参数。

以下代码仅适用于9.0.1。

假设:

<cfcache action="serverCache" timeout="#CreateTimeSpan(0,0,0,10)#" stripwhitespace="true" usequerystring="true"> 
Stuff to cache in the default store. 
<br/> 
<cfoutput>#Now()#</cfoutput> 
</cfcache> 

<cfcache action="serverCache" key="myCustomCache" timeout="#CreateTimeSpan(0,0,0,10)#" stripwhitespace="true" usequerystring="true"> 
Stuff to cache in the 'myCustomCache' store. 
<cfoutput>#Now()#</cfoutput> 
</cfcache> 

访问高速缓存分开

默认(模板)的标识符:

<cfdump var=#getAllTemplateCacheIds()#> 

myCustomCache:

<cfdump var=#cacheGetSession('myCustomCache',true).getKeys()#> 

读自定义缓存

<cfset keys = cacheGetSession('myCustomCache',true).getKeys() /> 

<cfcache key="myCustomCache" action="get" name="dataInCache" id="#keys[1]#"> 

<cfdump var=#dataInCache#> 

的数据独立地冲洗默认

<cfset cacheRemove(keys[1],true,'myCustomCache')> 

可悲的自定义缓存,文档不是处于最佳状态与问候的功能,用9.0.1进入。幸运的是,CF用户群擅长挖掘这些东西,即Rob-*s Bilson,他们在CF和缓存方面拥有许多优秀的文章。

夫妇的警告你应该以这种方式与缓存的工作要记住:

  1. 这些电话联系到了Ehcache引擎盖,这是Java的下,如果你尝试访问可能返回NULL值不存在的键。将结果包裹在IsNull()以验证。

  2. cacheGetSession()被误导(如罗布指出,在他的博客),你可能会认为您检索会话相关的缓存数据,因为它适用于您的应用程序,但事实并非如此 - 它是服务器范围内的,您将在共享应用程序环境中看到其他缓存的密钥。

所以,照顾到冲洗相应的数据 ...