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

/wheels/cache/storage/Ehcache.cfc

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