问题
I'm trying to use http://www.flexablecoder.com/blog/index.cfm/memcached client.
All works ok but for each cfm call, Coldfusion always open a new connection to the memcached server, not reusing an old one.
Is there a way to reuse the memcached connections?
回答1:
You need to initialize a singleton object, ie, only one instance of the memcached object. In application.cfc you can initialize in onApplicationStart method:
<cfset application.memcachedFactory = CreateObject("component","memcachedFactory").init("ip:port")>
<cfset application.memcached = application.memcachedFactory.getmemcached()>
If using application.cfm, just check the instance before setting it:
<cfif not IsDefined("application.memcached")>
<cfset application.memcachedFactory = createObject("component","memcachedFactory").init("ip:port")>
<cfset application.memcached = application.memcachedFactory.getmemcached()>
</cfif>
来源:https://stackoverflow.com/questions/8225948/coldfusion-memcached-connections