From 46b298be10dfb5cad34381ff2dccbab32369ce8f Mon Sep 17 00:00:00 2001 From: Zach Ferland Date: Tue, 20 Nov 2018 21:09:06 -0500 Subject: [PATCH] feat: allow local cache to be pass as option --- API.md | 2 ++ src/OrbitDB.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index 88f6921..37b2c3e 100644 --- a/API.md +++ b/API.md @@ -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).* diff --git a/src/OrbitDB.js b/src/OrbitDB.js index 4072915..7ca9e01 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -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)