これは私を夢中にさせています。CF memcached ラッパーの構築を試みました。次のような memcached.cfc コンポーネントがあります。
<cfset this.m = arraynew(1)>
<cffunction name="init" access="public" output="false">
<cfif not isdefined("application.memcached")
....
<cfscript>
setup();
</cfscript>
...
<cfset application.memcached = this>
</cfif>
<cfreturn application.memcached>
</cffunction>
<cffunction name="setup" access="private" output="false">
<cftry>
<cfset this.m = arraynew(1)>
<cfloop from="1" to="#this.poolSize#" index="i">
<cfset this.m[i] = createClient()>
</cfloop>
<cflog application="no" file="memcached" text="Successfully set up #this.poolSize# new memcache clients">
<cfcatch>
<cflog application="no" file="memcached" text="Exception in setup() while setting up the pool: type: #cfcatch.type#, message: #cfcatch.message#, detail: #cfcatch.detail#">
</cfcatch>
</cftry>
</cffunction>
<cffunction name="createClient" access="private" output="false">
<cfset var AU = createObject("java", "net.spy.memcached.AddrUtil").init()>
<cfset var c = createObject("java", "net.spy.memcached.MemcachedClient").init(AU.getAddresses("127.0.0.1:11211"))>
<cfreturn c>
</cffunction>
<cffunction name="getCache" access="public" returntype="any" output="false">
<cfset idx = ceiling(rand() * 20)>
<cfreturn application.memcached.m[idx]>
</cffunction>
奇妙なことは、30 分ほど実行した後、getCache が失敗し始め、idx の位置にある application.memcached.m 配列に項目がないということです。
これはどのように起こっているのでしょうか?CF配列は弱参照か何かを使用していますか? アレイに 20 個のクライアントが配置されると、アレイは常に満杯のままになるはずですか?
新しいクライアントごとに新しいスレッドが生成されるため、クライアントへの参照が失われると、クライアントをシャットダウンする方法があり、そのスレッドはそこに永久に残り、メモリを消費します。何が足りないのですか?