Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io / lib / stores / memory.js
1
2 /*!
3  * socket.io-node
4  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 /**
9  * Module dependencies.
10  */
11
12 var crypto = require('crypto')
13   , Store = require('../store');
14
15 /**
16  * Exports the constructor.
17  */
18
19 exports = module.exports = Memory;
20 Memory.Client = Client;
21
22 /**
23  * Memory store
24  *
25  * @api public
26  */
27
28 function Memory (opts) {
29   Store.call(this, opts);
30 };
31
32 /**
33  * Inherits from Store.
34  */
35
36 Memory.prototype.__proto__ = Store.prototype;
37
38 /**
39  * Publishes a message.
40  *
41  * @api private
42  */
43
44 Memory.prototype.publish = function () { };
45
46 /**
47  * Subscribes to a channel
48  *
49  * @api private
50  */
51
52 Memory.prototype.subscribe = function () { };
53
54 /**
55  * Unsubscribes
56  *
57  * @api private
58  */
59
60 Memory.prototype.unsubscribe = function () { };
61
62 /**
63  * Client constructor
64  *
65  * @api private
66  */
67
68 function Client () {
69   Store.Client.apply(this, arguments);
70   this.data = {};
71 };
72
73 /**
74  * Inherits from Store.Client
75  */
76
77 Client.prototype.__proto__ = Store.Client;
78
79 /**
80  * Gets a key
81  *
82  * @api public
83  */
84
85 Client.prototype.get = function (key, fn) {
86   fn(null, this.data[key] === undefined ? null : this.data[key]);
87   return this;
88 };
89
90 /**
91  * Sets a key
92  *
93  * @api public
94  */
95
96 Client.prototype.set = function (key, value, fn) {
97   this.data[key] = value;
98   fn && fn(null);
99   return this;
100 };
101
102 /**
103  * Has a key
104  *
105  * @api public
106  */
107
108 Client.prototype.has = function (key, fn) {
109   fn(null, key in this.data);
110 };
111
112 /**
113  * Deletes a key
114  *
115  * @api public
116  */
117
118 Client.prototype.del = function (key, fn) {
119   delete this.data[key];
120   fn && fn(null);
121   return this;
122 };
123
124 /**
125  * Destroys the client.
126  *
127  * @param {Number} number of seconds to expire data
128  * @api private
129  */
130
131 Client.prototype.destroy = function (expiration) {
132   if ('number' != typeof expiration) {
133     this.data = {};
134   } else {
135     var self = this;
136
137     setTimeout(function () {
138       self.data = {};
139     }, expiration * 1000);
140   }
141
142   return this;
143 };