Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SimpleCache = function() {
- var _values = {};
- var getTime = function() {
- return Date.now() / 1000 | 0
- }
- this.get = function(key) {
- if (!(key in _values)) {
- return null
- }
- var vl = _values[key];
- if (!vl.time) {
- return vl.value
- } else if (vl.time < getTime()) {
- this.remove(key)
- return null;
- } else {
- return vl.value
- }
- }
- this.remove = function(key) {
- delete _values[key];
- };
- this.set = function(key, value, time) {
- _values[key] = {
- 'time': time ? getTime() + time : 0,
- 'value': value
- };
- };
- this.values = function() { return _values; };
- }
Add Comment
Please, Sign In to add comment