experimenting with store-level caching...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-01 01:14:34 +03:00
parent 4059b988a9
commit 55e8daa4ce
5 changed files with 41 additions and 36 deletions

View File

@ -25,17 +25,23 @@ var pouchdbstore = require('./pwiki/store/pouchdb')
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var store = var store =
module.store = { /* XXX the store cache is not working correctly yet -- should be global
// XXX base localstorage... // and not local to a specific store...
// ...i.e. likely like MetaStore, it should be Level-2...
module.store = object.mixin({
__proto__: localstoragestore.localStorageStore, __proto__: localstoragestore.localStorageStore,
__prefix__: '--pwiki-root:', __prefix__: '--pwiki-root:',
data: localStorage, data: localStorage,
/*/ next: { __proto__: basestore.Store },
__proto__: basestore.MetaStore, }, basestore.CachedStoreMixin)
//*/ /*/
module.store = {
next: { __proto__: basestore.MetaStore }, __proto__: localstoragestore.localStorageStore,
__prefix__: '--pwiki-root:',
data: localStorage,
next: { __proto__: basestore.Store },
} }
//*/
module.setup = module.setup =
Promise.all([ Promise.all([

View File

@ -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 might be a fun idea to actually use this as a backend for BaseStore...
// XXX make this a mixin... // XXX make this a mixin...
// XXX add cache invalidation strategies... // XXX add cache invalidation strategies...
// - timeout // - timeout
// - count // - count
// XXX TEST... // XXX TEST...
var CachedStore = var CachedStoreMixin =
module.CachedStore = { module.CachedStoreMixin = {
__proto__: MetaStore, //__proto__: MetaStore,
// format: // format:
// { // {
// <path>: <value>, // <path>: <value>,
// } // }
__cache: undefined, __cache_data: undefined,
__paths: undefined, get __cache(){
return (this.__cache_data = this.__cache_data ?? {}) },
set __cache(value){
this.__cache_data = value },
resetCache: function(){ resetCache: function(){
delete this.__paths delete this.__cache_data
delete this.__cache
return this }, return this },
__paths__: function(){
return this.__paths
?? (this.__paths =
object.parentCall(CachedStore.__paths__, this)) },
__exists__: async function(path){ __exists__: async function(path){
return path in this.cache return path in this.__cache
|| object.parentCall(CachedStore.__exists__, this, path) }, || object.parentCall(CachedStoreMixin.__exists__, this, ...arguments) },
__get__: async function(path){ __get__: async function(path){
return this.cache[path] return this.__cache[path]
?? (this.cache[path] = ?? (this.__cache[path] =
object.parentCall(CachedStore.__get__, this, path, ...args)) }, await object.parentCall(CachedStoreMixin.__get__, this, ...arguments)) },
__update__: async function(path, data){ __update__: async function(path, data){
this.__paths.includes(path) // XXX this is wrong???
|| this.__paths.push(path)
this.__cache[path] = data this.__cache[path] = data
return object.parentCall(CachedStore.__update__, this, path, data) }, return object.parentCall(CachedStoreMixin.__update__, this, ...arguments) },
__delete__: async function(path){ __delete__: async function(path){
var i = this.__paths.indexOf(path)
i > 0
&& this.__paths.splice(i, 1)
delete this.__cache[path] 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 }) * vim:set ts=4 sw=4 : */ return module })

View File

@ -520,8 +520,7 @@ module.backup = {
// XXX add monitor API + cache + live mode (auto on when lock detected)... // XXX add monitor API + cache + live mode (auto on when lock detected)...
var FileStoreRO = var FileStoreRO =
module.FileStoreRO = { module.FileStoreRO = {
//__proto__: base.BaseStore, __proto__: base.Store,
__proto__: base.MetaStore,
// XXX // XXX
__path__: 'data/fs', __path__: 'data/fs',

View File

@ -20,8 +20,7 @@ var base = require('./base')
// XXX EXPERIMENTAL, needs testing in browser... // XXX EXPERIMENTAL, needs testing in browser...
var localStorageStore = var localStorageStore =
module.localStorageStore = { module.localStorageStore = {
//__proto__: base.BaseStore, __proto__: base.Store,
__proto__: base.MetaStore,
__prefix__: '--pwiki:', __prefix__: '--pwiki:',
// XXX add caching of unserialized data??? // XXX add caching of unserialized data???

View File

@ -20,8 +20,7 @@ var PouchDB = require('pouchdb')
var PouchDBStore = var PouchDBStore =
module.PouchDBStore = { module.PouchDBStore = {
//__proto__: base.BaseStore, __proto__: base.Store,
__proto__: base.MetaStore,
// XXX should this be __path__??? // XXX should this be __path__???
// ...this sets the path where the store is created... // ...this sets the path where the store is created...