PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/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
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. <cfscript>
  4. variables.$instance = {};
  5. variables.$instance.cache = {};
  6. </cfscript>
  7. <cfreturn this>
  8. </cffunction>
  9. <cffunction name="isAvailable" access="public" output="false" returntype="boolean">
  10. <cfreturn StructKeyExists(variables, "$instance") && StructKeyExists(variables.$instance, "cache")>
  11. </cffunction>
  12. <cffunction name="set" access="public" output="false" returntype="void">
  13. <cfargument name="key" type="string" required="true">
  14. <cfargument name="value" type="any" required="true">
  15. <cfscript>
  16. variables.$instance.cache[arguments.key] = arguments.value;
  17. </cfscript>
  18. </cffunction>
  19. <cffunction name="get" access="public" output="false" returntype="any">
  20. <cfargument name="key" type="string" required="true">
  21. <cfscript>
  22. var loc = {};
  23. loc.value = false;
  24. if (StructKeyExists(variables.$instance.cache, arguments.key))
  25. {
  26. if (IsSimpleValue(variables.$instance.cache[arguments.key]))
  27. {
  28. loc.value = variables.$instance.cache[arguments.key];
  29. }
  30. else
  31. {
  32. loc.value = Duplicate(variables.$instance.cache[arguments.key]);
  33. }
  34. }
  35. </cfscript>
  36. <cfreturn loc.value>
  37. </cffunction>
  38. <cffunction name="evict" access="public" output="false" returntype="numeric">
  39. <cfargument name="keys" type="array" required="false" default="#ArrayNew(1)#">
  40. <cfargument name="strategy" type="any" required="true">
  41. <cfargument name="currentTime" type="date" required="true">
  42. <cfscript>
  43. var loc = {};
  44. if (ArrayIsEmpty(arguments.keys))
  45. arguments.keys = ListToArray(StructKeyList(variables.$instance.cache));
  46. loc.expiredKeys = arguments.strategy.getExpired(keys=arguments.keys, storage=this, currentTime=arguments.currentTime);
  47. for (loc.i = 1; loc.i lte ArrayLen(loc.expiredKeys); loc.i++)
  48. delete(key=loc.expiredKeys[loc.i]);
  49. </cfscript>
  50. <cfreturn ArrayLen(loc.expiredKeys)>
  51. </cffunction>
  52. <cffunction name="delete" access="public" output="false" returntype="void">
  53. <cfargument name="key" type="string" required="true">
  54. <cfscript>
  55. StructDelete(variables.$instance.cache, arguments.key, false);
  56. </cfscript>
  57. </cffunction>
  58. <cffunction name="count" access="public" output="false" returntype="numeric">
  59. <cfreturn StructCount(variables.$instance.cache) />
  60. </cffunction>
  61. <cffunction name="flush" access="public" output="false" returntype="void">
  62. <cfset StructClear(variables.$instance.cache)>
  63. </cffunction>
  64. </cfcomponent>