diff --git a/browser.js b/browser.js index 6662ec6..fec3932 100755 --- a/browser.js +++ b/browser.js @@ -25,17 +25,23 @@ var pouchdbstore = require('./pwiki/store/pouchdb') //--------------------------------------------------------------------- var store = -module.store = { - // XXX base localstorage... +/* XXX the store cache is not working correctly yet -- should be global +// and not local to a specific store... +// ...i.e. likely like MetaStore, it should be Level-2... +module.store = object.mixin({ __proto__: localstoragestore.localStorageStore, __prefix__: '--pwiki-root:', data: localStorage, - /*/ - __proto__: basestore.MetaStore, - //*/ - - next: { __proto__: basestore.MetaStore }, + next: { __proto__: basestore.Store }, +}, basestore.CachedStoreMixin) +/*/ +module.store = { + __proto__: localstoragestore.localStorageStore, + __prefix__: '--pwiki-root:', + data: localStorage, + next: { __proto__: basestore.Store }, } +//*/ module.setup = Promise.all([ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 3f617dc..bd0d13e 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -704,54 +704,56 @@ module.MetaStore = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// XXX should this be a level-1 or level-2??? // XXX might be a fun idea to actually use this as a backend for BaseStore... // XXX make this a mixin... // XXX add cache invalidation strategies... // - timeout // - count // XXX TEST... -var CachedStore = -module.CachedStore = { - __proto__: MetaStore, +var CachedStoreMixin = +module.CachedStoreMixin = { + //__proto__: MetaStore, // format: // { // : , // } - __cache: undefined, - __paths: undefined, + __cache_data: undefined, + get __cache(){ + return (this.__cache_data = this.__cache_data ?? {}) }, + set __cache(value){ + this.__cache_data = value }, resetCache: function(){ - delete this.__paths - delete this.__cache + delete this.__cache_data return this }, - __paths__: function(){ - return this.__paths - ?? (this.__paths = - object.parentCall(CachedStore.__paths__, this)) }, __exists__: async function(path){ - return path in this.cache - || object.parentCall(CachedStore.__exists__, this, path) }, + return path in this.__cache + || object.parentCall(CachedStoreMixin.__exists__, this, ...arguments) }, __get__: async function(path){ - return this.cache[path] - ?? (this.cache[path] = - object.parentCall(CachedStore.__get__, this, path, ...args)) }, + return this.__cache[path] + ?? (this.__cache[path] = + await object.parentCall(CachedStoreMixin.__get__, this, ...arguments)) }, __update__: async function(path, data){ - this.__paths.includes(path) - || this.__paths.push(path) + // XXX this is wrong??? this.__cache[path] = data - return object.parentCall(CachedStore.__update__, this, path, data) }, + return object.parentCall(CachedStoreMixin.__update__, this, ...arguments) }, __delete__: async function(path){ - var i = this.__paths.indexOf(path) - i > 0 - && this.__paths.splice(i, 1) delete this.__cache[path] - return object.parentCall(CachedStore.__delete__, this, path) }, + return object.parentCall(CachedStoreMixin.__delete__, this, ...arguments) }, } +//--------------------------------------------------------------------- + +var Store = +module.Store = + MetaStore + + /********************************************************************** * vim:set ts=4 sw=4 : */ return module }) diff --git a/pwiki/store/file.js b/pwiki/store/file.js index 528f1c6..41821a8 100755 --- a/pwiki/store/file.js +++ b/pwiki/store/file.js @@ -520,8 +520,7 @@ module.backup = { // XXX add monitor API + cache + live mode (auto on when lock detected)... var FileStoreRO = module.FileStoreRO = { - //__proto__: base.BaseStore, - __proto__: base.MetaStore, + __proto__: base.Store, // XXX __path__: 'data/fs', diff --git a/pwiki/store/localstorage.js b/pwiki/store/localstorage.js index c974bd0..33384be 100755 --- a/pwiki/store/localstorage.js +++ b/pwiki/store/localstorage.js @@ -20,8 +20,7 @@ var base = require('./base') // XXX EXPERIMENTAL, needs testing in browser... var localStorageStore = module.localStorageStore = { - //__proto__: base.BaseStore, - __proto__: base.MetaStore, + __proto__: base.Store, __prefix__: '--pwiki:', // XXX add caching of unserialized data??? diff --git a/pwiki/store/pouchdb.js b/pwiki/store/pouchdb.js index c54a17a..8b2ffe1 100755 --- a/pwiki/store/pouchdb.js +++ b/pwiki/store/pouchdb.js @@ -20,8 +20,7 @@ var PouchDB = require('pouchdb') var PouchDBStore = module.PouchDBStore = { - //__proto__: base.BaseStore, - __proto__: base.MetaStore, + __proto__: base.Store, // XXX should this be __path__??? // ...this sets the path where the store is created...