Created
December 3, 2010 14:44
-
-
Save atuttle/727040 to your computer and use it in GitHub Desktop.
Simple cache manager for ColdFusion. Relies on the user to store the component instance in a persistent scope (eg Application, Server, or Session)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component output="false" { | |
public function init(){ | |
variables.cache={}; | |
return this; | |
} | |
public void function put(key, data, timeout){ | |
variables.cache[key] = { timeout=arguments.timeout, data=arguments.data }; | |
} | |
public boolean function has(key){ | |
return (structKeyExists(variables.cache, arguments.key) && dateCompare(now(),variables.cache[arguments.key].timeout) == -1); | |
} | |
public function get(key){ | |
if (has(arguments.key)){ | |
return variables.cache[arguments.key]; | |
}else{ | |
throw(message="Key does not exist or cache has timed out.", errorCode=-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment