feat: allow local cache to be pass as option

This commit is contained in:
Zach Ferland
2018-11-20 21:09:06 -05:00
parent b819a66208
commit 46b298be10
2 changed files with 4 additions and 1 deletions

2
API.md
View File

@@ -75,6 +75,8 @@ Creates and returns an instance of OrbitDB. Use the optional `directory` argumen
- `keystore` (Keystore Instance) : By default creates an instance of [Keystore](https://github.com/orbitdb/orbit-db-keystore). A custom keystore instance can be used, see [this](https://github.com/orbitdb/orbit-db/blob/master/test/utils/custom-test-keystore.js) for an example.
- 'cache' (Cache Instance) : By default creates an instance of [Cache](https://github.com/orbitdb/orbit-db-cache). A custom cache instance can also be used.
After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a [database instance](#store-api). See the [Store](#store-api) section for details of common methods and properties.
*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).*

View File

@@ -37,6 +37,7 @@ class OrbitDB {
this.stores = {}
this.directory = directory || './orbitdb'
this.keystore = options.keystore || Keystore.create(path.join(this.directory, this.id, '/keystore'))
this.cache = options.cache || Cache
this.key = this.keystore.getKey(this.id) || this.keystore.createKey(this.id)
this._directConnections = {}
}
@@ -348,7 +349,7 @@ class OrbitDB {
async _loadCache (directory, dbAddress) {
let cache
try {
cache = await Cache.load(directory, dbAddress)
cache = await this.cache.load(directory, dbAddress)
} catch (e) {
console.log(e)
logger.error("Couldn't load Cache:", e)