1
+ /** @module cacheManager/caching */
1
2
/*jshint maxcomplexity:15*/
2
3
var domain = require ( 'domain' ) ;
3
4
var CallbackFiller = require ( './callback_filler' ) ;
@@ -6,9 +7,7 @@ var CallbackFiller = require('./callback_filler');
6
7
* Generic caching interface that wraps any caching library with a compatible interface.
7
8
*
8
9
* @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.
12
11
* @param {function } [args.isCacheableValue] - A callback function which is called
13
12
* with every value returned from cache or from a wrapped function. This lets you specify
14
13
* which values should and should not be cached. If the function returns true, it will be
@@ -48,8 +47,15 @@ var caching = function(args) {
48
47
* its results are stored in cache so subsequent calls retrieve from cache
49
48
* instead of calling the function.
50
49
*
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
52
57
*
58
+ * @example
53
59
* var key = 'user_' + userId;
54
60
* cache.wrap(key, function(cb) {
55
61
* User.get(userId, cb);
@@ -100,26 +106,61 @@ var caching = function(args) {
100
106
} ) ;
101
107
} ;
102
108
109
+ /**
110
+ * Binds to the underlying store's `get` function.
111
+ * @function
112
+ * @name get
113
+ */
103
114
self . get = self . store . get . bind ( self . store ) ;
104
115
116
+ /**
117
+ * Binds to the underlying store's `set` function.
118
+ * @function
119
+ * @name set
120
+ */
105
121
self . set = self . store . set . bind ( self . store ) ;
106
122
123
+ /**
124
+ * Binds to the underlying store's `del` function if it exists.
125
+ * @function
126
+ * @name del
127
+ */
107
128
if ( typeof self . store . del === 'function' ) {
108
129
self . del = self . store . del . bind ( self . store ) ;
109
130
}
110
131
132
+ /**
133
+ * Binds to the underlying store's `setex` function if it exists.
134
+ * @function
135
+ * @name setex
136
+ */
111
137
if ( typeof self . store . setex === 'function' ) {
112
138
self . setex = self . store . setex . bind ( self . store ) ;
113
139
}
114
140
141
+ /**
142
+ * Binds to the underlying store's `reset` function if it exists.
143
+ * @function
144
+ * @name reset
145
+ */
115
146
if ( typeof self . store . reset === 'function' ) {
116
147
self . reset = self . store . reset . bind ( self . store ) ;
117
148
}
118
149
150
+ /**
151
+ * Binds to the underlying store's `keys` function if it exists.
152
+ * @function
153
+ * @name keys
154
+ */
119
155
if ( typeof self . store . keys === 'function' ) {
120
156
self . keys = self . store . keys . bind ( self . store ) ;
121
157
}
122
158
159
+ /**
160
+ * Binds to the underlying store's `ttl` function if it exists.
161
+ * @function
162
+ * @name ttl
163
+ */
123
164
if ( typeof self . store . ttl === 'function' ) {
124
165
self . ttl = self . store . ttl . bind ( self . store ) ;
125
166
}
0 commit comments