Coldfusion memcached连接 [英] Coldfusion memcached connections

查看:359
本文介绍了Coldfusion memcached连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 http://www.flexablecoder.com/blog/ index.cfm / memcached 客户端。

所有工作都正常,但对于每个cfm调用,Coldfusion总是打开一个到memcached服务器的新连接,而不是重用一个旧的。

All works ok but for each cfm call, Coldfusion always open a new connection to the memcached server, not reusing an old one.

是否有办法重用memcached连接?

Is there a way to reuse the memcached connections?

推荐答案

您需要初始化一个单例对象,即只有一个memcached对象的实例。在application.cfc中,您可以在onApplicationStart方法中初始化:

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()>

如果使用application.cfm,只需检查实例,然后再设置:

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>

这篇关于Coldfusion memcached连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆