Fix cache path problems

This commit is contained in:
haad 2016-11-03 09:35:38 +01:00
parent f7c19eb9b6
commit 1709be97fe
5 changed files with 29 additions and 20 deletions

6
.gitignore vendored
View File

@ -5,11 +5,9 @@ node_modules/
.idea/
dump.rdb
Vagrantfile
orbit-db-cache.json
examples/browser/bundle.js
examples/browser/*.map
dist/*.map
orbit-db.json
dist/orbitdb.js
orbit-db.cache
ipfs/
orbit-db/
ipfs/

19
dist/orbitdb.js vendored
View File

@ -4655,11 +4655,15 @@ var Cache = function () {
}
}, {
key: 'loadCache',
value: function loadCache() {
var cacheFile = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'orbit-db.cache';
value: function loadCache(cachePath) {
var cacheFile = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'orbit-db.cache';
cache = {};
store = new BlobStore(cacheFile);
if (!cachePath) return _promise2.default.resolve();
// console.log("cache data:", cachePath)
store = new BlobStore(cachePath);
filePath = cacheFile;
return new _promise2.default(function (resolve, reject) {
@ -4688,6 +4692,7 @@ var Cache = function () {
key: 'reset',
value: function reset() {
cache = {};
store = null;
}
}]);
return Cache;
@ -25609,17 +25614,17 @@ var OrbitDB = function () {
}, {
key: '_createStore',
value: function _createStore(Store, dbname) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { subscribe: true, cacheFile: 'orbit-db.json' };
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { subscribe: true };
var store = new Store(this._ipfs, this.user.id, dbname, options);
this.stores[dbname] = store;
return this._subscribe(store, dbname, options.subscribe, options);
return this._subscribe(store, dbname, options.subscribe, options.cachePath);
}
}, {
key: '_subscribe',
value: function _subscribe(store, dbname) {
var subscribe = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var options = arguments[3];
var cachePath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : './orbit-db';
store.events.on('data', this._onData.bind(this));
store.events.on('write', this._onWrite.bind(this));
@ -25629,7 +25634,7 @@ var OrbitDB = function () {
return console.error(e.stack);
});
Cache.loadCache(options.cacheFile).then(function () {
Cache.loadCache(cachePath).then(function () {
var hash = Cache.get(dbname);
store.loadHistory(hash).catch(function (e) {
return console.error(e.stack);

6
dist/orbitdb.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -37,9 +37,14 @@ class Cache {
return cache[key]
}
static loadCache(cacheFile = 'orbit-db.cache') {
static loadCache(cachePath, cacheFile = 'orbit-db.cache') {
cache = {}
store = new BlobStore(cacheFile)
if (!cachePath)
return Promise.resolve()
// console.log("cache data:", cachePath)
store = new BlobStore(cachePath)
filePath = cacheFile
return new Promise((resolve, reject) => {
@ -70,6 +75,7 @@ class Cache {
static reset() {
cache = {}
store = null
}
}

View File

@ -56,13 +56,13 @@ class OrbitDB {
}
/* Private methods */
_createStore(Store, dbname, options = { subscribe: true, cacheFile: 'orbit-db.json' }) {
_createStore(Store, dbname, options = { subscribe: true }) {
const store = new Store(this._ipfs, this.user.id, dbname, options)
this.stores[dbname] = store
return this._subscribe(store, dbname, options.subscribe, options)
return this._subscribe(store, dbname, options.subscribe, options.cachePath)
}
_subscribe(store, dbname, subscribe = true, options) {
_subscribe(store, dbname, subscribe = true, cachePath = './orbit-db') {
store.events.on('data', this._onData.bind(this))
store.events.on('write', this._onWrite.bind(this))
store.events.on('close', this._onClose.bind(this))
@ -72,7 +72,7 @@ class OrbitDB {
else
store.loadHistory().catch((e) => console.error(e.stack))
Cache.loadCache(options.cacheFile).then(() => {
Cache.loadCache(cachePath).then(() => {
const hash = Cache.get(dbname)
store.loadHistory(hash).catch((e) => console.error(e.stack))
})