Coldfusion memcached connections

青春壹個敷衍的年華 提交于 2019-12-25 01:56:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!