PageRenderTime 20ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/cache/strategy/Age.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 43 lines | 38 code | 4 blank | 1 comment | 9 complexity | 18ea2078c4cc764ebf17d58c6bd4e43e MD5 | raw file
 1<cfcomponent extends="BaseStrategy" implements="AbstractStrategy" output="false">
 2
 3	<cffunction name="getExpired" access="public" output="false" returntype="array">
 4		<cfargument name="keys" type="array" required="true">
 5		<cfargument name="storage" type="any" required="true">
 6		<cfargument name="currentTime" type="date" required="true">
 7		<cfscript>
 8			var loc = {};
 9			loc.expiredKeys = [];
10			if ((variables.$instance.cacheCullPercentage gt 0 
11					&& variables.$instance.cacheLastCulledAt < DateAdd("n", -variables.$instance.cacheCullInterval, arguments.currentTime) 
12					&& arguments.storage.count() gte variables.$instance.maximumItemsToCache)
13				|| ArrayLen(arguments.keys) == 1)
14			{
15				// cache is full so flush out expired items from this cache to make more room if possible
16				for (loc.i = 1; loc.i lte ArrayLen(arguments.keys); loc.i++)
17				{
18					loc.key = arguments.keys[loc.i];
19					loc.cacheItem = arguments.storage.get(loc.key);
20					
21					if (arguments.currentTime gt loc.cacheItem.expiresAt)
22					{
23						ArrayAppend(loc.expiredKeys, loc.key);
24						if (variables.$instance.cacheCullPercentage < 100)
25						{
26							loc.percentageDeleted = (ArrayLen(loc.expiredKeys) / ArrayLen(arguments.keys)) * 100;
27							if (loc.percentageDeleted gte variables.$instance.cacheCullPercentage)
28								break;
29						}
30					}
31				}
32				variables.$instance.cacheLastCulledAt = arguments.currentTime;				
33			}
34		</cfscript>
35		<cfreturn loc.expiredKeys>
36	</cffunction>
37	
38	<cffunction name="checkExpired" access="public" output="false" returntype="array">
39		<cfargument name="value" type="struct" required="true">
40		<cfargument name="storage" type="AbstractStorage" required="true">
41	</cffunction>
42
43</cfcomponent>