Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added YUI cache per req context #506

Merged
merged 6 commits into from

2 participants

This page is out of date. Refresh to see the latest.
View
2  lib/app/autoload/action-context.common.js
@@ -225,7 +225,6 @@ YUI.add('mojito-action-context', function(Y, NAME) {
for (addonName in dependencies) {
if (dependencies.hasOwnProperty(addonName)) {
-
if (mods.indexOf(addonName + '-addon') > -1 || addonName === 'core') {
addon = new addons[addonName](command, adapter, ac);
if (addon.namespace) {
@@ -235,7 +234,6 @@ YUI.add('mojito-action-context', function(Y, NAME) {
}
}
}
-
}
}
}
View
47 lib/app/autoload/dispatch.common.js
@@ -21,8 +21,7 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
logger,
store,
CACHE = {
- YUI: {},
- controllerContexts: {}
+ YUI: {}
},
// TODO: [Issue 112] remove client detection logic
cacheControllerContext = (typeof window !== 'undefined'),
@@ -31,7 +30,6 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
useOnDemand,
appShareYUIInstance;
-
/* Optimization methods:
============ 1). YUI({bootstrap:false}).use('*')
@@ -90,31 +88,52 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
modules: instance.yui.config.modules
};
+ // Abstract the key generation in mojito-util which is already loaded,
+ command.yuiCacheKey = Y.mojito.util.createCacheKey(command.context);
+
+ // We replace the given instance with the expanded instance
+ command.instance = instance;
+
// Create our own YUI sandbox
// yuiObj = YUI();
// yuiObj.applyConfig(yuiConfig);
// Use a single YUI sandbox
- yuiObj = yuiOnce;
+ // yuiObj = yuiOnce;
+ // One YUI instance per context
+ yuiObj = CACHE.YUI[command.yuiCacheKey];
+ if (undefined === yuiObj) {
+ yuiObj = YUI();
+ CACHE.YUI[command.yuiCacheKey] = yuiObj;
+ // console.log('Create new YUI instance for : ' + instance.type);
+ // } else {
+ // console.log('Using cached YUI instance');
+ }
yuiObj.applyConfig(yuiConfig);
- // We replace the given instance with the expanded instance
- command.instance = instance;
-
// Copy this or else it pollutes the client runtime
yuiModules = Y.mojito.util.copy(instance.yui.sorted);
// Create the function that will be called in YUI().use()
yuiModules.push(function (MOJIT_Y) {
- var controller;
+ var controller,
+ ac;
- if (controllers[instance.type]) {
- controller = controllers[instance.type];
- } else {
- controller = MOJIT_Y.mojito.controllers[instance['controller-module']];
- controllers[instance.type] = controller; //Y.mojito.util.heir(controller);
- }
+ //
+ // if (controllers[instance.type]) {
+ // controller = controllers[instance.type];
+ // } else {
+ // controller = MOJIT_Y.mojito.controllers[instance['controller-module']];
+ // controllers[instance.type] = controller; //Y.mojito.util.heir(controller);
+ // }
+
+ controller = MOJIT_Y.mojito.controllers[command.instance['controller-module']];
+ // controller = CACHE.controllers[instance.type];
+ // if (undefined === controller) {
+ // controller = MOJIT_Y.mojito.controllers[command.instance['controller-module']];
+ // CACHE.controllers[instance.type] = controller;
+ // }
// var c = MOJIT_Y.mojito.controllers[instance['controller-module']],
// controller = Y.mojito.util.heir(c); // cache this and test based on config key
View
19 lib/app/autoload/util.common.js
@@ -421,10 +421,29 @@ YUI.add('mojito-util', function(Y) {
return false;
}
return appShareYUIInstance || false;
+ },
+
+ /**
+ * Given an object, generate a key that can be used for cache lookup
+ *
+ * @method createKey
+ * @param obj {Object}
+ * @return {String}
+ */
+ createCacheKey: function(obj) {
+ var key;
+ // TODO: should check if obj is of type Object vs try/catch
+ try {
+ key = Y.JSON.stringify(obj);
+ } catch (err) {
+ key = Y.guid();
+ }
+ return key;
}
};
}, '0.1.0', {requires: [
'array-extras',
+ 'json-stringify',
'mojito'
]});
Something went wrong with that request. Please try again.