PageRenderTime 32ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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