diff --git a/Viewer/features/core.js b/Viewer/features/core.js index 4ee804de..cb6bc5ef 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -440,7 +440,8 @@ module.Logger = ImageGridFeatures.Feature({ // right at the string start. // // XXX might be a good idea to move this to a more generic spot like lib/util.js... -var doc = module.doc = object.doc +//var doc = module.doc = object.doc +var doc = module.doc = actions.doc var text = module.text = object.text @@ -1045,6 +1046,9 @@ module.Serialization = ImageGridFeatures.Feature({ // XXX would be nice to have a simple cachedAction(name, cache-tag, expire, func) // action wrapper that would not require anything from the action and // just not call it if already called... +// ...to do this we'll need to be able to select a value by args +// from the cache this will require a diff mattch or something +// similar... var CacheActions = actions.Actions({ config: { // Enable/disable caching... @@ -1092,51 +1096,55 @@ var CacheActions = actions.Actions({ // XXX handler cache.. }, - // Cache utility method... - // - // .cache(title, handler) - // -> value - // - // .cache(group, title, handler) - // -> value - // - // - // Example use: - // someAction: [ - // function(){ - // return this.cache('someAction', - // function(data){ - // if(data){ - // // clone/update the data... - // // NOTE: this should be faster than the construction - // // branch below or this will defeat the purpose - // // of caching... - // ... - // - // } else { - // // get the data... - // ... - // } - // return data - // }) }], - // - // XXX what should the default group be??? - // XXX should this be an action??? __cache: null, - cache: function(title, handler){ - var group = 'global' - // caching disabled... - if(!(this.config || {}).cache){ - return handler.call(this) } - arguments.length > 2 - && ([group, title, handler] = arguments) - var cache = this.__cache = this.__cache || {} - cache = cache[group] = cache[group] || {} - return (cache[title] = - title in cache ? - // pass the cached data for cloning/update to the handler... - handler.call(this, cache[title]) - : handler.call(this)) }, + cache: doc('Get or set cache value', + doc`Get or set cache value + + .cache(title, handler) + -> value + + .cache(group, title, handler) + -> value + + + Example use: + someAction: [ + function(){ + return this.cache('someAction', + function(data){ + if(data){ + // clone/update the data... + // NOTE: this should be faster than the construction + // branch below or this will defeat the purpose + // of caching... + ... + + } else { + // get the data... + ... + } + return data + }) }], + + + NOTE: since this is here to help speed things up, introducing a + small but not necessary overhead by making this an action is + not logical... + `, + function(title, handler){ + var group = 'global' + // caching disabled... + if(!(this.config || {}).cache){ + return handler.call(this) } + arguments.length > 2 + && ([group, title, handler] = arguments) + var cache = this.__cache = this.__cache || {} + cache = cache[group] = cache[group] || {} + return (cache[title] = + title in cache ? + // pass the cached data for cloning/update to the handler... + handler.call(this, cache[title]) + : handler.call(this)) }), clearCache: ['System/Clear cache', doc` diff --git a/Viewer/package-lock.json b/Viewer/package-lock.json index d6f25c76..52a03eff 100755 --- a/Viewer/package-lock.json +++ b/Viewer/package-lock.json @@ -1073,11 +1073,11 @@ "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "ig-actions": { - "version": "3.24.18", - "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.18.tgz", - "integrity": "sha512-0cZYX56el81rOGcD/GwFsrD4pRg3ZwYu7ilSzkXhZTw+mvGQD7Vilj1faHrWTX2geMS3XugZ/294dP/Jl6VGDg==", + "version": "3.24.19", + "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.19.tgz", + "integrity": "sha512-b4Lz4qD/aw7MOcNDgGn/y6992EjeFHQw6tmv1AfX1ZeWdpg9TjPjkdFy5NLpdGknURM/b1I06AkxYLgBAeOQyQ==", "requires": { - "ig-object": "^5.0.2" + "ig-object": "^5.4.12" } }, "ig-argv": { diff --git a/Viewer/package.json b/Viewer/package.json index a112581a..54176f73 100755 --- a/Viewer/package.json +++ b/Viewer/package.json @@ -28,7 +28,7 @@ "generic-walk": "^1.4.0", "glob": "^7.1.6", "guarantee-events": "^1.0.0", - "ig-actions": "^3.24.18", + "ig-actions": "^3.24.19", "ig-argv": "^2.15.0", "ig-features": "^3.4.2", "ig-object": "^5.4.12",