Skip to content

Instantly share code, notes, and snippets.

@atuttle
Created December 3, 2010 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atuttle/727040 to your computer and use it in GitHub Desktop.
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)
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