mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-30 02:20:08 +00:00 
			
		
		
		
	experimenting with store-level caching...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									4059b988a9
								
							
						
					
					
						commit
						55e8daa4ce
					
				
							
								
								
									
										20
									
								
								browser.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								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([ | ||||
|  | ||||
| @ -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:
 | ||||
| 	// 	{
 | ||||
| 	// 		<path>: <value>,
 | ||||
| 	// 	}
 | ||||
| 	__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 }) | ||||
|  | ||||
| @ -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', | ||||
|  | ||||
| @ -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???
 | ||||
|  | ||||
| @ -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...
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user