<commit_before>
var createModuleInstance = require('./composition');
var hub = require('./client/hub');
var utils = require('./client/utils');
var Cache = require('./cache');

var instance_cache = Cache('module_instances', true);

/**
 * Check if role has access to instance and event.
 *
 * @public
 * @param {string} The role name.
 * @param {string} The module instance name.
 * @param {string} The event name.
 */
exports.eventAccess = function (role, module_instance, event) {

    // get instance with role check
    module_instance = instance_cache.get(module_instance, role);

    // check if this instance has acces to the requested operation
    if (module_instance &&  module_instance._access && module_instance._access[event]) {
        return module_instance;
    }

    return;
};

/**
 * The module instance factory.
 *
 * @public
 * @param {object} The module instance composition.
 * @param {function} The callback function.
 */
exports.factory = function (composition) {

    // create new module instance
    var module_instance = utils.clone(Hub);

    // save composition data on the module instance
    module_instance._name = composition.name;
    module_instance._roles = composition.roles || {};
    module_instance._client = composition.client || {};
    module_instance._config = composition.config || {};
    module_instance._links = {};<commit_msg>make instance cache global, for flow "to" config<commit_after>
var createModuleInstance = require('./composition');
var hub = require('./client/hub');
var utils = require('./client/utils');
var Cache = require('./cache');

var instance_cache = engine.instances = Cache('module_instances', true);

/**
 * Check if role has access to instance and event.
 *
 * @public
 * @param {string} The role name.
 * @param {string} The module instance name.
 * @param {string} The event name.
 */
exports.eventAccess = function (role, module_instance, event) {

    // get instance with role check
    module_instance = instance_cache.get(module_instance, role);

    // check if this instance has acces to the requested operation
    if (module_instance &&  module_instance._access && module_instance._access[event]) {
        return module_instance;
    }

    return;
};

/**
 * The module instance factory.
 *
 * @public
 * @param {object} The module instance composition.
 * @param {function} The callback function.
 */
exports.factory = function (composition) {
  
    // 1. check Cache
    // 2. get composition
    // 3. create module instance

    // create new module instance
    var module_instance = utils.clone(Hub);

    // save composition data on the module instance
    module_instance._name = composition.name;
    module_instance._roles = composition.roles || {};
    module_instance._client = composition.client || {};
    module_instance._config = composition.config || {};
    module_instance._links = {};
{'fraction_non_alphanumeric': 0.12171507607192254, 'fraction_numerical': 0.001037344398340249, 'mean_word_length': 3.592063492063492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3776206', 'n_tokens_mistral': 775, 'n_tokens_neox': 761, 'n_words': 248}