PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/wheels/vendor/memcached/MemcachedFactory.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 57 lines | 50 code | 6 blank | 1 comment | 4 complexity | 42ed757c71897680bc67c8959bce6276 MD5 | raw file
 1<cfcomponent name="MemcachedFactory" hint="The Factory for Memcached, should be a scope singleton">
 2	
 3	<cfscript>
 4		instance = StructNew();
 5		FactoryServers = "";
 6		FactoryTimeout = 0;
 7		FactoryUnit = "";
 8	</cfscript>
 9	
10	<cffunction name="init" access="public" returntype="MemcachedFactory" output="false"
11		hint="Our constructor.">
12		<cfargument name="servers" type="string" required="false" hint="comma delimited list of servers" />
13		<cfargument name="defaultTimeout" type="numeric" required="false" default="-1" 
14				hint="the number of nano/micro/milli/seconds to wait for the response.  
15				a timeout setting of 0 will wait forever for a response from the server
16				*** this defaults to 400  ***
17				"/>
18		<cfargument name="defaultUnit" type="string" required="false" default=""
19				hint="The timeout unit to use for the timeout this will 
20					*** this defaults to milliseconds ***
21				"/>
22		<!--- <cfargument name="servers" type="array" required="false" /> --->
23		<cfscript>
24			// if (structKeyExists(arguments, "servers")) { }
25			
26			if (NOT structKeyExists(arguments, "servers") or listlen(arguments.servers) eq 0) {
27				arguments.servers = "127.0.0.1:11211";
28			}
29			
30			setMemcached(createObject("component", "com.Memcached").init(arguments.servers));
31			if (arguments.defaultTimeout gt -1)	{
32				instance.Memcached.setDefaultRequestTimeout = arguments.defaultTimeout;
33			}
34			if (len(trim(arguments.defaultUnit)))	{
35				instance.Memcached.setDefaultTimeoutUnit = arguments.defaultUnit;
36			}
37			FactoryServers = arguments.servers;
38			FactoryTimeout = arguments.defaultTimeout;
39			FactoryUnit = arguments.defaultUnit;
40			return this;
41		</cfscript>
42	</cffunction>
43
44	<cffunction name="getMemcached" access="public" returntype="any" output="false"
45		hint="Returns the main library class, that is used in all processing" >
46		<cfif not StructkeyExists(instance,"Memcached") or isSimpleValue(instance.Memcached)>
47			<!------------ if we can't find the instance.Memcached object, then i guess we need to reinit---->
48			<cfset this.init()>
49		</cfif>
50		<cfreturn instance.Memcached />
51	</cffunction>
52	
53	<cffunction name="setMemcached" access="private" returntype="void" output="false">
54		<cfargument name="Memcached" type="any" required="true" />
55		<cfset instance.Memcached = arguments.Memcached />
56	</cffunction>
57</cfcomponent>