Skip to content

Commit a5138b7

Browse files
committed
adding jsdocs support
1 parent 62c3a29 commit a5138b7

File tree

8 files changed

+84
-13
lines changed

8 files changed

+84
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
coverage
33
.idea
44
*.iml
5+
out

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ BASE = .
33
ISTANBUL = ./node_modules/.bin/istanbul
44
COVERAGE_OPTS = --lines 99 --statements 95 --branches 90 --functions 95
55

6-
main: lint test
6+
main: lint test docs
77

88
cover:
99
$(ISTANBUL) cover test/run.js
@@ -28,5 +28,8 @@ lint:
2828
./node_modules/.bin/jshint ./test --config $(BASE)/.jshintrc
2929
./node_modules/.bin/jshint ./examples --config $(BASE)/.jshintrc
3030

31+
docs:
32+
./node_modules/.bin/jsdoc lib --recurse --readme README.md --package package.json
33+
echo docs available in ./out/index.html
3134

3235
.PHONY: test

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ var multiCache = cacheManager.multiCaching([memoryCache, someOtherCache], {
242242

243243
```
244244
245+
## Docs
246+
247+
To generate JSDOC 3 documentation:
248+
249+
make docs
245250
246251
## Tests
247252

index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
var cache = {
2-
caching: require('./lib/caching'),
3-
multi_caching: require('./lib/multi_caching'), //backward compat
4-
multiCaching: require('./lib/multi_caching')
5-
};
6-
7-
module.exports = cache;
1+
module.exports = require('./lib');

lib/caching.js

+45-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @module cacheManager/caching */
12
/*jshint maxcomplexity:15*/
23
var domain = require('domain');
34
var CallbackFiller = require('./callback_filler');
@@ -6,9 +7,7 @@ var CallbackFiller = require('./callback_filler');
67
* Generic caching interface that wraps any caching library with a compatible interface.
78
*
89
* @param {object} args
9-
* @param {object|string} args.store - The store must have at least the following functions:
10-
* - set
11-
* - get
10+
* @param {object|string} args.store - The store must at least have `set` and a `get` functions.
1211
* @param {function} [args.isCacheableValue] - A callback function which is called
1312
* with every value returned from cache or from a wrapped function. This lets you specify
1413
* which values should and should not be cached. If the function returns true, it will be
@@ -48,8 +47,15 @@ var caching = function(args) {
4847
* its results are stored in cache so subsequent calls retrieve from cache
4948
* instead of calling the function.
5049
*
51-
* @example
50+
* @function
51+
* @name wrap
52+
*
53+
* @param {string} key - The cache key to use in cache operations
54+
* @param {function} work - The function to wrap
55+
* @param {object} [options] - options passed to `set` function
56+
* @param {function} cb
5257
*
58+
* @example
5359
* var key = 'user_' + userId;
5460
* cache.wrap(key, function(cb) {
5561
* User.get(userId, cb);
@@ -100,26 +106,61 @@ var caching = function(args) {
100106
});
101107
};
102108

109+
/**
110+
* Binds to the underlying store's `get` function.
111+
* @function
112+
* @name get
113+
*/
103114
self.get = self.store.get.bind(self.store);
104115

116+
/**
117+
* Binds to the underlying store's `set` function.
118+
* @function
119+
* @name set
120+
*/
105121
self.set = self.store.set.bind(self.store);
106122

123+
/**
124+
* Binds to the underlying store's `del` function if it exists.
125+
* @function
126+
* @name del
127+
*/
107128
if (typeof self.store.del === 'function') {
108129
self.del = self.store.del.bind(self.store);
109130
}
110131

132+
/**
133+
* Binds to the underlying store's `setex` function if it exists.
134+
* @function
135+
* @name setex
136+
*/
111137
if (typeof self.store.setex === 'function') {
112138
self.setex = self.store.setex.bind(self.store);
113139
}
114140

141+
/**
142+
* Binds to the underlying store's `reset` function if it exists.
143+
* @function
144+
* @name reset
145+
*/
115146
if (typeof self.store.reset === 'function') {
116147
self.reset = self.store.reset.bind(self.store);
117148
}
118149

150+
/**
151+
* Binds to the underlying store's `keys` function if it exists.
152+
* @function
153+
* @name keys
154+
*/
119155
if (typeof self.store.keys === 'function') {
120156
self.keys = self.store.keys.bind(self.store);
121157
}
122158

159+
/**
160+
* Binds to the underlying store's `ttl` function if it exists.
161+
* @function
162+
* @name ttl
163+
*/
123164
if (typeof self.store.ttl === 'function') {
124165
self.ttl = self.store.ttl.bind(self.store);
125166
}

lib/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @namespace cacheManager */
2+
var cacheManager = {
3+
caching: require('./caching'),
4+
// Deprecate
5+
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
6+
multi_caching: require('./multi_caching'), //backward compat
7+
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
8+
multiCaching: require('./multi_caching')
9+
};
10+
11+
module.exports = cacheManager;

lib/multi_caching.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
/** @module cacheManager/multiCaching */
12
var async = require('async');
23
var domain = require('domain');
34
var CallbackFiller = require('./callback_filler');
45

56
/**
6-
*
77
* Module that lets you specify a hierarchy of caches.
8+
*
9+
* @memberof cacheManager
10+
*
811
* @param {array} caches - Array of caching objects.
912
* @param {object} [options]
1013
* @param {function} [options.isCacheableValue] - A callback function which is called
@@ -177,6 +180,10 @@ var multiCaching = function(caches, options) {
177180

178181
/**
179182
* Set value in all caches
183+
*
184+
* @function
185+
* @name set
186+
*
180187
* @param {string} key
181188
* @param {*} value
182189
* @param {object} [options] to pass to underlying set function.
@@ -196,6 +203,10 @@ var multiCaching = function(caches, options) {
196203

197204
/**
198205
* Get value from highest level cache that has stored it.
206+
*
207+
* @function
208+
* @name get
209+
*
199210
* @param {string} key
200211
* @param {object} [options] to pass to underlying get function.
201212
* @param {function} cb
@@ -210,6 +221,10 @@ var multiCaching = function(caches, options) {
210221

211222
/**
212223
* Delete value from all caches.
224+
*
225+
* @function
226+
* @name del
227+
*
213228
* @param {string} key
214229
* @param {object} [options] to pass to underlying del function.
215230
* @param {function} cb

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"coveralls": "^2.3.0",
2828
"istanbul": "^0.2.11",
2929
"jscs": "^1.9.0",
30+
"jsdoc": "^3.3.0",
3031
"jshint": "^2.5.4",
3132
"mocha": "^1.20.1",
3233
"optimist": "^0.6.1",

0 commit comments

Comments
 (0)