Created
April 26, 2014 05:14
-
-
Save blindman2k/11312312 to your computer and use it in GitHub Desktop.
Agent persistent storage class
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
class Persist { | |
cache = null; | |
// ------------------------------------------------------------------------- | |
function read(key = null, def = null) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
return (key in cache) ? cache[key] : def; | |
} | |
// ------------------------------------------------------------------------- | |
function write(key, value) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
if (key in cache) { | |
server.save(cache); | |
} else { | |
cache[key] <- value; | |
server.save(cache); | |
} | |
return value; | |
} | |
// ------------------------------------------------------------------------- | |
function remove(key) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
if (key in cache) { | |
delete cache[key]; | |
server.save(cache); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment