caching - 如何在部署过程中清除 ColdFusion 模板缓存?

标签 caching coldfusion cfc

我今天早上在将一些文件部署到 ColdFusion 网站/应用程序后遇到了一个问题。

我用一些新代码更新了现有的 CFC。 CFC 有一个返回实例化对象的 init() 方法:

原始 MyObject.cfc:

<cfscript>
    VARIABLES.MyParam = "";
</cfscript>

<cffunction name="init" returntype="MyObject" output="false">
    <cfargument name="MyParam" type="String" required="true" />

    <cfscript>
        VARIABLES.MyParam = ARGUMENTS.MyParam;

        return THIS;
    </cfscript>
</cffunction>

新建 MyObject.cfc:

<cfscript>
    VARIABLES.MyParam = "";
</cfscript>

<cffunction name="init" returntype="MyObject" output="false">
    <cfargument name="MyParam" type="String" required="true" />

    <cfscript>
        setMyParam(ARGUMENTS.MyParam);

        return THIS;
    </cfscript>
</cffunction>

<cffunction name="setMyParam" output="false" returntype="Void">
    <cfargument name="MyParam" type="String" required="true" />

    <cfset VARIABLES.MyParam = Trim(ARGUMENTS.MyParam) />
</cffunction>

<cffunction name="getMyParam" output="false" returntype="String">
    <cfreturn VARIABLES.MyParam />
</cffunction>

只要扩展此 CFC 的对象调用 init(),它就会抛出异常:

"The value returned from the init function is not of type MyObject."

此问题未发生在部署此更改的任何其他环境中 - 仅发生在生产环境中。

唯一修复它的方法是清除 ColdFusion Administrator 中的模板缓存。

因此,我正在寻找一种方法来防止这种情况在未来发生,和/或一种在我部署文件时自动清除模板缓存的方法。

仅供引用,我目前使用 Tortoise SVN 部署文件。

最佳答案

在您的 init() 中(或者更优选地,在另一个重载式方法中),以编程方式调用 Admin API 的 clearTrustedCache() 方法:

<cfscript>

     // Login is always required (if the administrator password 
     // is enabled in the ColdFusion Administrator). 
     // This example uses two lines of code. 

     adminObj = createObject("component","cfide.adminapi.administrator");
     adminObj.login("admin");

     // Instantiate the runtime object. 
     myObj = createObject("component","cfide.adminapi.runtime");

     // clear cache 
     myObj.clearTrustedCache();

     // Stop and restart trusted cache. However, only the clearTrustedCache function needs to be called.
     myObj.setCacheProperty("TrustedCache", 0);
     myObj.setCacheProperty("TrustedCache", 1);
</cfscript>

此功能早在 CF7 ( Source ) 就已存在。请注意,为此您需要 CF 管理员密码。

如果您在管理员中启用了该选项,我还建议您清除组件缓存:

    myObj.clearComponentCache();

关于caching - 如何在部署过程中清除 ColdFusion 模板缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10620808/

相关文章:

IOS WKWebview缓存清理

cocoa - 创建 CGImageRef 而不缓存任何内容

coldfusion - CFC 从哪里获得它的应用范围

coldfusion - 在另一个文件夹级别调用 CFC

coldfusion - 这些 ColdFusion 组件之间有什么区别吗?

php - 缓存以减少负载(PHP 和 MYSQL)

python - 为什么 python3 lru_cache 不提供 put 和 query 方法?

coldfusion - 尝试通过 CF10 管理员更新时出现错误 "Failed Signature verification"

c# - 公共(public)证书在 WCF 中扮演什么角色?

java - 在 Lucee 上安装 Cassandra Java 驱动程序