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

Caching 是否可以解析ColdFusion 9.0.1缓存内存的内容?,caching,memory,coldfusion,cfcache,Caching,Memory,Coldfusion,Cfcache,我对从CF8到9的更改视而不见,在这里,如果不创建自定义缓存或其他一些不值得付出努力的激烈解决方法,写入磁盘缓存将不再可能 此时,我放弃了将应用程序转换为支持(如果可能的话)将缓存文件的内容写入静态cfm文件的相同方法。我现在更好奇了,因为我已经深入研究了它。我在找一个比我更有经验的人 我想了解或知道如何使用模板缓存: 能够以默认或自定义缓存中的模板为目标,并在不清除整个缓存的情况下刷新它 出于好奇或调试方法,查看或分析特定缓存模板的内容 这就是我使用的代码,需要CF 9.0.1,因为我相信由于

我对从CF8到9的更改视而不见,在这里,如果不创建自定义缓存或其他一些不值得付出努力的激烈解决方法,写入磁盘缓存将不再可能

此时,我放弃了将应用程序转换为支持(如果可能的话)将缓存文件的内容写入静态cfm文件的相同方法。我现在更好奇了,因为我已经深入研究了它。我在找一个比我更有经验的人

我想了解或知道如何使用模板缓存:

  • 能够以默认或自定义缓存中的模板为目标,并在不清除整个缓存的情况下刷新它
  • 出于好奇或调试方法,查看或分析特定缓存模板的内容
  • 这就是我使用的代码,需要CF 9.0.1,因为我相信由于添加了EhCache 2.0,9.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>
    
    
    要缓存的东西。
    
    #现在()#
    cacheArray=GetAllTemplateCacheId(); 写输出(“在
    之前”; 对于(i=1;i LTE阵列(缓存阵列);i=i+1) { 写输出(cacheArray[i]&“
    ”; if(FindNoCase(scriptPath,cacheArray[i])) { //期望每个字符串只找到一个最小值和一个最大值,所以不必担心越界 cacheIDSubStr=REFind(“[a-fA-F\d]{32}(?=\u行:\d*$)”,cacheArray[i],1,1); cacheID=Mid(cacheArray[i],CacheIDSubStr.pos[1],CacheIDSubStr.len[1]); //删除缓存失败 //写输出(cacheID&“
    ”); //cacheObject=CacheGet(cacheID); //CacheRemove(cacheID); templateCache=cacheGetSession(“模板”); //利用cacheGetSession的暴露核心进行工作 WriteMap(templateCache.getKeys()); } } writeoutput(“错误:&cfcatch.message”);

    不应存在任何错误,但它是从原始版本编辑到此处发布的。

    秘密在于CF 9.0.1函数
    cacheGetSession()
    ,以及对其他函数的修改,以将
    键作为参数

    以下代码仅适用于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>
    
    
    要缓存在默认存储中的内容。
    
    #现在()# 要在“myCustomCache”存储中缓存的内容。 #现在()#
    分别访问缓存的标识符

    默认值(模板):

    
    
    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用户库擅长挖掘这些东西,也就是说,他有很多关于CF和缓存的优秀文章

    在以这种方式使用缓存时,应记住以下几点注意事项:

  • 这些调用绑定到引擎盖下的EhCache,即Java,如果您试图访问不存在的密钥,则可能返回null。将结果包装在
    IsNull()
    中进行验证

  • cacheGetSession()具有误导性(正如Rob在他的博客中指出的那样),您可能认为您正在检索应用于应用程序的与会话相关的缓存数据,但事实并非如此——它是服务器范围的,您将在共享应用程序环境中看到其他缓存的密钥

  • 所以,注意刷新适当的数据

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