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