Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mojito-cache

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mojito-cache - npm Package Compare versions

Comparing version 0.0.6 to 0.1.0

2

package.json
{
"name": "mojito-cache",
"version": "0.0.6",
"version": "0.1.0",
"description": "A set of libraries for various caching strategies in mojito.",

@@ -5,0 +5,0 @@ "main": " ",

@@ -32,2 +32,3 @@ /*jslint nomen: true, indent: 4, plusplus: true, stupid: true */

this.typeCacheUsed = false;
this.__callIsUsed = false;
this.cachedAc = {

@@ -53,2 +54,5 @@ command: {

self.baseCacheUsed = true;
},
__call: function () {
self.__callIsUsed = true;
}

@@ -70,7 +74,2 @@ }

Y.mojito.Dispatcher.store = {
getStaticAppConfig: function () {
return self.CONFIG;
}
};
Y.mojito.addons.ac = {

@@ -146,3 +145,2 @@ baz: BazAddon,

'Both Base and type: Base overrides Type': function () {
var self = this;

@@ -160,2 +158,5 @@ Y.mojito.Dispatcher.dispatch({

}
},
page: {
staticAppConfig: this.CONFIG
}

@@ -181,2 +182,5 @@ });

}
},
page: {
staticAppConfig: this.CONFIG
}

@@ -201,2 +205,5 @@ });

}
},
page: {
staticAppConfig: this.CONFIG
}

@@ -209,2 +216,47 @@ });

'Unknown action, __call is called': function () {
Y.mojito.Dispatcher.dispatch({
instance: {
base: 'foo',
action: 'unkownAction'
}
}, {
req: {
globals: {
'request-cache': this.cache
}
},
page: {
staticAppConfig: this.CONFIG
}
});
A.isTrue(this.__callIsUsed);
},
'Unknown action, and no __call, error is thrown': function () {
try {
Y.mojito.Dispatcher.dispatch({
instance: {
type: 'Bar',
action: 'unkownAction'
}
}, {
req: {
globals: {
'request-cache': this.cache
}
},
page: {
staticAppConfig: this.CONFIG
}
});
} catch (e) {
A.pass();
return;
}
A.fail('An error should have been thrown earlier');
},
'Correct Addons are refreshed': function () {

@@ -222,2 +274,5 @@

}
},
page: {
staticAppConfig: this.CONFIG
}

@@ -224,0 +279,0 @@ });

@@ -19,2 +19,11 @@ /*

/**
* Here we will mimic what the ActionContext constructor does,
* except we try to skip expanding the instance and repopulating the
* addons if we don't have to. We build a cache in the request
* object, which means this is useful for apps that have several
* times the same type of mojit on the same page. The cache does not
* survive the current request.
* @see: ActionContext constructor
*/
this.dispatch = function (command, adapter) {

@@ -25,2 +34,4 @@

newCommand,
action,
error,
i,

@@ -32,3 +43,3 @@ addonName,

// Build cache if it doesn't exist.
// Build the cache if it doesn't exist.
adapter.req.globals = adapter.req.globals || {};

@@ -51,4 +62,5 @@

// If this is the first ever call to dispatch, we retrieve that list from the config
if (!refreshedAddons) {
staticAppConfig = this.store.getStaticAppConfig();
staticAppConfig = adapter.page.staticAppConfig;
refreshedAddons = staticAppConfig['request-cache'] && staticAppConfig['request-cache'].refreshAddons;

@@ -60,5 +72,6 @@ if (!refreshedAddons) {

// We reference this here just to easily refer
// to cachedResource.actionContext.command
newCommand = cachedResource.actionContext.command;
// debugger;
// We want the new params and action

@@ -68,9 +81,9 @@ newCommand.params = command.params;

// This is specific to mojito-pipeline
newCommand.task = command.task;
// Reap anything else that might have gone into the instance config.
Y.mix(newCommand.instance.config, command.instance.config, true);
// Instantiate again the addons that need to be refreshed
// Instantiate again the addons that need to be refreshed if any
for (i = 0; i < refreshedAddons.length; i++) {

@@ -91,11 +104,57 @@ AddonConstuct = Y.mojito.addons.ac[refreshedAddons[i]];

// @see: ActionContext constructor
// TODO: handle __call
// TODO: handle staticAppConfig.actionTimeout
// Handle the __call case
if (Y.Lang.isFunction(cachedResource.controller[newCommand.action])) {
cachedResource.controller[newCommand.action](cachedResource.actionContext);
action = newCommand.action;
} else if (Y.Lang.isFunction(cachedResource.controller.__call)) {
action = '__call';
} else {
error = new Error("No method '" + newCommand.action + "' on controller type '" + newCommand.instance.type + "'");
error.code = 404;
throw error;
}
// Handle controller timeout
if (adapter.page.staticAppConfig.actionTimeout) {
// This will be cleared in ActionContext.done if it happens in time
cachedResource.actionContext._timer = setTimeout(function () {
var err,
msg = 'Killing potential zombie context for Mojit type: ' +
command.instance.type +
', controller: ' + cachedResource.controller +
', action: ' + action;
// Clear the timer reference so our invocation of error()
// doesn't try to clear it.
cachedResource.actionContext._timer = null;
// Create an HTTP Timeout error with controller/action info.
err = new Error(msg);
err.code = 408;
cachedResource.actionContext.error(err);
// Unlike what we do in the normal AC, this is not done because
// we reuse that action context!
// That might screw up some rendering though...
// cachedResource.actionContext.done = function() {
// Y.log('ac.done() called after timeout. results lost', 'warn', NAME);
// };
}, adapter.page.staticAppConfig.actionTimeout);
}
cachedResource.controller[action](cachedResource.actionContext);
} else {
// Expands the command.instance and creates a new AC
// which in turn instanciates all the addons and calls the controller
// No cache, expand the command.instance and create a new AC
// with our custom RequestCacheActionContext constructor
// which then instanciates all the addons and calls the controller
// This is normal mojito workflow, except our custom constructor
// populates the cache so next time we can find it and avoid
// doing this.
originalDispatcher.dispatch.apply(this, arguments);

@@ -102,0 +161,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc