// cache data
var caches = {};

/**
 * The object cache factory.
 *
 * @public
 * @param {string} The unique file cache name.
 * @param {boolean} Check role or not.
 */
module.exports = function factory (name, checkRole) {

    // return existing cache
    if (caches[name]) {
        return caches[name];
    }

    // clone cache class
    var cache = engine.clone(Cache);

    // create data container
    cache._data = {};

    // check role access
    cache._roleCheck = checkRole;

    // save cache
    caches[name] = cache;

    return cache;
};

/**
 * The object cache class.
 *
 * @class Cache
 */
var Cache = {

    /**
     * Remove an object, or with no argument empty the cache.
     *
     * @public
     * @param {string} The file path.
     */
    rm: function (key, role) {

        // remove one item
        if (key) {

            // return if key does not exists
            if (this._data[key] === undefined) {
                return;
            }

            // check role access
            if (this._roleCheck && !checkRoleAccess(this._data[key], role)) {
                return 0;
            }

            return delete this._data[key];
        }

        // remove all items
        this._data = {};
    },

    /**
     * Get an object, or get all objects in the cache.
     *
     * @public
     * @param {string} The file path.
     */
    get: function (key, role) {

        // return one item
        if (key) {

            // return if key does not exists
            if (this._data[key] === undefined) {
                return;
            }

            // check role access
            if (this._roleCheck && !checkRoleAccess(this._data[key], role)) {
                return 0;
            }

            return this._data[key];
        }

        // return all items
        return this._data;
    },

     /**
     * Save an object in the cache.
     *
     * @public
     * @param {string} The object name.
     * @param {object} The data object.
     */
    set: function (key, data) {

        if (key) {
            this._data[key] = data;
        }
    }
};

/**
 * Check the role access for a cache item.
 *
 * @private
 * @param {object} The cached item.
 * @param {string} The role name.
 */
function checkRoleAccess (item, role) {

    if (item._roles['*'] || (item._roles && item._roles[role])) {
        return true;
    }
}

@@ -1028,38 +1028,40 @@
 ._roleCheck && !
-checkR
+engine.r
 oleAccess(this._
@@ -1649,22 +1649,24 @@
 eck && !
-checkR
+engine.r
 oleAcces
@@ -2107,280 +2107,7 @@
   %7D%0A
+
 %7D;%0A
-%0A/**%0A * Check the role access for a cache item.%0A *%0A * @private%0A * @param %7Bobject%7D The cached item.%0A * @param %7Bstring%7D The role name.%0A */%0Afunction checkRoleAccess (item, role) %7B%0A%0A    if (item._roles%5B'*'%5D %7C%7C (item._roles && item._roles%5Brole%5D)) %7B%0A        return true;%0A    %7D%0A%7D%0A

check role access with the "engine.roleAccess" function