Skip to content

Commit

Permalink
adding storage.create factory method, related to simonlast#39
Browse files Browse the repository at this point in the history
  • Loading branch information
akhoury committed Jul 14, 2015
1 parent 0b7cf73 commit ac3041a
Show file tree
Hide file tree
Showing 4 changed files with 873 additions and 716 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,20 @@ storage.setItem('name','myname');
storage.persistKeySync('name');
```

### Factory method

#### `create(options)` - synchronous, static method

If you choose to create multiple instances of storage, you can. Just avoid using the same `dir` for the storage location.
__You still have to call `init` or `initSync` after `create`__ - you can pass your configs to either `create` or `init/Sync`

The reason we don't call `init` in the constructor (or when you `create`) because we can only do so for the `initSync` version, the async `init` returns a promise, and in order to maintain that API, we cannot return the promise in the constructor, so `init` must be called on the instance of new LocalStorage();

```javascript
var storage = require('node-persist');
var myStorage = storage.create({dir: 'myDir', ttl: 3000});
myStorage.init().then(function() { // or you can use initSync()
// ...
});
```
##### [Simon Last](http://simonlast.org)
Loading

0 comments on commit ac3041a

Please sign in to comment.