PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent implements="AbstractStorage" output="false">
  2. <cffunction name="init" access="public" output="false" returntype="any">
  3. <cfargument name="timeSpan" type="numeric" required="false" default="#application.wheels.defaultCacheTime#">
  4. <cfargument name="idleTime" type="numeric" required="false" default="240">
  5. <cfscript>
  6. variables.$instance = {};
  7. variables.$instance.timeSpan = CreateTimeSpan(0, 0, arguments.timeSpan, 0);
  8. variables.$instance.idleTime = CreateTimeSpan(0, 0, arguments.idleTime, 0);
  9. </cfscript>
  10. <cfreturn this>
  11. </cffunction>
  12. <cffunction name="isAvailable" access="public" output="false" returntype="boolean">
  13. <cfreturn StructKeyExists(GetFunctionList(), "cacheGet")>
  14. </cffunction>
  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. CachePut(arguments.key, arguments.value, variables.$instance.timeSpan, variables.$instance.idleTime);
  20. </cfscript>
  21. </cffunction>
  22. <cffunction name="get" access="public" output="false" returntype="any">
  23. <cfargument name="key" type="string" required="true">
  24. <cfscript>
  25. var loc = {};
  26. loc.value = CacheGet(arguments.key);
  27. if (!StructKeyExists(loc, "value"))
  28. loc.value = false;
  29. </cfscript>
  30. <cfreturn loc.value>
  31. </cffunction>
  32. <cffunction name="evict" access="public" output="false" returntype="numeric">
  33. <cfargument name="keys" type="array" required="false" default="#ArrayNew(1)#">
  34. <cfargument name="strategy" type="any" required="true">
  35. <cfargument name="currentTime" type="date" required="true">
  36. <cfscript>
  37. var loc = {};
  38. if (ArrayIsEmpty(arguments.keys))
  39. arguments.keys = CacheGetAllIds();
  40. loc.expiredKeys = arguments.strategy.getExpired(keys=arguments.keys, storage=this, currentTime=arguments.currentTime);
  41. for (loc.i = 1; loc.i lte ArrayLen(loc.expiredKeys); loc.i++)
  42. delete(key=loc.expiredKeys[loc.i]);
  43. </cfscript>
  44. <cfreturn ArrayLen(loc.expiredKeys)>
  45. </cffunction>
  46. <cffunction name="delete" access="public" output="false" returntype="void">
  47. <cfargument name="key" type="string" required="true">
  48. <cfscript>
  49. CacheRemove(arguments.key, false);
  50. </cfscript>
  51. </cffunction>
  52. <cffunction name="count" access="public" output="false" returntype="numeric">
  53. <cfreturn ArrayLen(CacheGetAllIds()) />
  54. </cffunction>
  55. <cffunction name="flush" access="public" output="false" returntype="void">
  56. <cfscript>
  57. var loc = {};
  58. loc.keys = CacheGetAllIds();
  59. for (loc.i = 1; loc.i lte ArrayLen(loc.keys); loc.i++)
  60. delete(loc.keys[loc.i]);
  61. </cfscript>
  62. </cffunction>
  63. </cfcomponent>