/
MemoryStorage.js
62 lines (54 loc) · 1.39 KB
/
MemoryStorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* This file is part of the Spludo Framework.
* Copyright (c) 2009-2010 DracoBlue, http://dracoblue.net/
*
* Licensed under the terms of MIT License. For the full copyright and license
* information, please see the LICENSE file in the root folder.
*/
/**
* @class The memory storage.
*/
MemoryStorage = function(name, options) {
this.values = {};
this.setOptions(options);
storage_manager.addStorage(name, this);
};
extend(true, MemoryStorage.prototype, Options.prototype, Logging.prototype);
MemoryStorage.prototype.set = function(key, value) {
var self = this;
return function(cb) {
self.values[key] = value;
cb(true);
};
};
MemoryStorage.prototype.get = function(key) {
var self = this;
return function(cb) {
if (typeof self.values[key] === 'undefined') {
cb();
} else {
cb(self.values[key]);
}
};
};
MemoryStorage.prototype.has = function(key) {
var self = this;
return function(cb) {
if (typeof self.values[key] === 'undefined') {
cb(false);
} else {
cb(true);
}
};
};
MemoryStorage.prototype.remove = function(key) {
var self = this;
return function(cb) {
if (typeof self.values[key] === 'undefined') {
cb(false);
} else {
delete self.values[key];
cb(true);
}
};
};