File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,12 @@ KeyValueMemoryConnector.prototype.disconnect = function(callback) {
201201 process . nextTick ( callback ) ;
202202} ;
203203
204+ KeyValueMemoryConnector . prototype . flush =
205+ function ( modelName , options , callback ) {
206+ this . _store = Object . create ( null ) ;
207+ callback ( ) ;
208+ } ;
209+
204210function StoreItem ( value , ttl ) {
205211 this . value = value ;
206212 this . setTtl ( ttl ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var assert = require ( 'assert' ) ;
4+ var utils = require ( '../utils' ) ;
5+
6+ /**
7+ * Delete all keys (and values) associated to the current model.
8+ *
9+ * @options {Object} options Unused ATM, placeholder for future options.
10+ * @callback {Function } callback
11+ * @param {Error } err Error object.
12+ * @promise
13+ *
14+ * @header KVAO.prototype.flush(options, cb)
15+ */
16+ module . exports = function flush ( options , callback ) {
17+ if ( callback == undefined && typeof options === 'function' ) {
18+ callback = options ;
19+ options = { } ;
20+ } else if ( ! options ) {
21+ options = { } ;
22+ }
23+
24+ assert ( typeof options === 'object' , 'options must be an object' ) ;
25+
26+ callback = callback || utils . createPromiseCallback ( ) ;
27+
28+ this . getConnector ( ) . flush ( this . modelName , options , callback ) ;
29+ return callback . promise ;
30+ } ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = KeyValueAccessObject;
88KeyValueAccessObject . get = require ( './get' ) ;
99KeyValueAccessObject . set = require ( './set' ) ;
1010KeyValueAccessObject . expire = require ( './expire' ) ;
11+ KeyValueAccessObject . flush = require ( './flush' ) ;
1112KeyValueAccessObject . ttl = require ( './ttl' ) ;
1213KeyValueAccessObject . iterateKeys = require ( './iterate-keys' ) ;
1314KeyValueAccessObject . keys = require ( './keys' ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const bdd = require ( '../helpers/bdd-if' ) ;
4+ const helpers = require ( './_helpers' ) ;
5+ const should = require ( 'should' ) ;
6+
7+ module . exports = function ( dataSourceFactory , connectorCapabilities ) {
8+ var supportsFlushOperation =
9+ connectorCapabilities . supportsFlushOperation !== false ;
10+
11+ bdd . describeIf ( supportsFlushOperation , 'flush' , function ( ) {
12+ let CacheItem ;
13+ beforeEach ( function unpackContext ( ) {
14+ CacheItem = helpers . givenCacheItem ( dataSourceFactory ) ;
15+ } ) ;
16+
17+ it ( 'removes all associated keys for a given model' , function ( ) {
18+ return helpers . givenKeys ( CacheItem , [ 'key1' , 'key2' ] )
19+ . then ( ( ) => CacheItem . flush ( ) )
20+ . then ( ( ) => CacheItem . keys ( ) )
21+ . done ( ( keys ) => {
22+ should ( keys ) . eql ( [ ] ) ;
23+ } ) ;
24+ } ) ;
25+ } ) ;
26+ } ;
You can’t perform that action at this time.
0 commit comments