1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | 'use strict';
|
21 |
|
22 | var MemoryStore = exports.MemoryStore = function (opts) {
|
23 | this._store = {};
|
24 | };
|
25 |
|
26 | MemoryStore.prototype.get = function (domain, key, cb) {
|
27 | var d = domain.toLowerCase();
|
28 | var k = key.toLowerCase();
|
29 | var result = this._store[d];
|
30 |
|
31 | if (result)
|
32 | result = result[k];
|
33 |
|
34 | process.nextTick(function () {
|
35 | cb(null, result);
|
36 | });
|
37 | };
|
38 |
|
39 | MemoryStore.prototype.set = function (domain, key, data, cb) {
|
40 | var d = domain.toLowerCase();
|
41 | var k = key.toLowerCase();
|
42 | var result_domain = this._store[d];
|
43 |
|
44 | if (!result_domain)
|
45 | result_domain = this._store[d] = {};
|
46 |
|
47 | result_domain[k] = data;
|
48 |
|
49 | if (cb) {
|
50 | process.nextTick(function () {
|
51 | cb(null, data);
|
52 | });
|
53 | }
|
54 | };
|
55 |
|
56 | MemoryStore.prototype.delete = function (domain, key, type, cb) {
|
57 | var d, k;
|
58 |
|
59 | if (!cb) {
|
60 | cb = type;
|
61 | type = undefined;
|
62 | }
|
63 |
|
64 | if (!cb) {
|
65 | cb = key;
|
66 | type = undefined;
|
67 | }
|
68 |
|
69 | d = this._store[domain.toLowerCase()];
|
70 |
|
71 | if (d && key)
|
72 | k = d[key.toLowerCase()];
|
73 |
|
74 | if (domain && key && type) {
|
75 | if (d && k) {
|
76 | delete k[type];
|
77 | }
|
78 | } else if (domain && key) {
|
79 | if (d) {
|
80 | delete d[k];
|
81 | }
|
82 | } else if (domain) {
|
83 | if (d) {
|
84 | delete this._store[domain.toLowerCase()];
|
85 | }
|
86 | }
|
87 |
|
88 | if (cb) {
|
89 | process.nextTick(function () {
|
90 | cb(null, domain);
|
91 | });
|
92 | }
|
93 | };
|