PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/cache/storage/Memory.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 77 lines | 64 code | 13 blank | 0 comment | 5 complexity | 5c30402298021ffa7b9aef9183252832 MD5 | raw file
 1<cfcomponent implements="AbstractStorage" output="false">
 2	
 3	<cffunction name="init" access="public" output="false" returntype="any">
 4		<cfscript>
 5			variables.$instance = {};
 6			variables.$instance.cache = {};
 7		</cfscript>
 8		<cfreturn this>
 9	</cffunction>
10	
11	<cffunction name="isAvailable" access="public" output="false" returntype="boolean">
12		<cfreturn StructKeyExists(variables, "$instance") && StructKeyExists(variables.$instance, "cache")>
13	</cffunction>
14	
15	<cffunction name="set" access="public" output="false" returntype="void">
16		<cfargument name="key" type="string" required="true">
17		<cfargument name="value" type="any" required="true">
18		<cfscript>
19			variables.$instance.cache[arguments.key] = arguments.value;
20		</cfscript>
21	</cffunction>
22	
23	<cffunction name="get" access="public" output="false" returntype="any">
24		<cfargument name="key" type="string" required="true">
25		<cfscript>
26			var loc = {};
27			loc.value = false;
28			
29			if (StructKeyExists(variables.$instance.cache, arguments.key))
30			{
31				if (IsSimpleValue(variables.$instance.cache[arguments.key]))
32				{
33					loc.value = variables.$instance.cache[arguments.key];
34				}
35				else
36				{
37					loc.value = Duplicate(variables.$instance.cache[arguments.key]);
38				}
39			}
40		</cfscript>
41		<cfreturn loc.value>
42	</cffunction>
43	
44	<cffunction name="evict" access="public" output="false" returntype="numeric">
45		<cfargument name="keys" type="array" required="false" default="#ArrayNew(1)#">
46		<cfargument name="strategy" type="any" required="true">
47		<cfargument name="currentTime" type="date" required="true">
48		<cfscript>
49			var loc = {};
50			
51			if (ArrayIsEmpty(arguments.keys))
52				arguments.keys = ListToArray(StructKeyList(variables.$instance.cache));
53			
54			loc.expiredKeys = arguments.strategy.getExpired(keys=arguments.keys, storage=this, currentTime=arguments.currentTime);
55			
56			for (loc.i = 1; loc.i lte ArrayLen(loc.expiredKeys); loc.i++)
57				delete(key=loc.expiredKeys[loc.i]);
58		</cfscript>
59		<cfreturn ArrayLen(loc.expiredKeys)>
60	</cffunction>
61	
62	<cffunction name="delete" access="public" output="false" returntype="void">
63		<cfargument name="key" type="string" required="true">
64		<cfscript>
65			StructDelete(variables.$instance.cache, arguments.key, false);
66		</cfscript>
67	</cffunction>
68	
69	<cffunction name="count" access="public" output="false" returntype="numeric">
70		<cfreturn StructCount(variables.$instance.cache) />
71	</cffunction>
72	
73	<cffunction name="flush" access="public" output="false" returntype="void">
74		<cfset StructClear(variables.$instance.cache)>
75	</cffunction>
76	
77</cfcomponent>