return typeof scope === "object" ? scope : this.getDefaultCacheScope();
},
getDefaultCacheScope: function () {
if (typeof window.Enw !== "object") {
window.Enw = {};
}
return window.Enw;
},
getCache: function (scope) {
var _scope = this.getCacheScope(scope);
if (!_scope.cache) {
_scope.cache = {};
_scope.cacheStack = [];
this.setCacheSize(this.getCacheSize(_scope), _scope);
}
return _scope.cache;
},
getCacheRest: function (scope) {
var _scope = this.getCacheScope(scope);
return _scope.cacheRest;
},
setToCache: function (key, val, scope) {
var _scope = this.getCacheScope(scope),
cache = this.getCache(scope),
limit = _scope.cacheSize,
size = this.sizeOf(val);
this.delFromCache(key, _scope);
if (size <= limit && !!key) {
if (size > _scope.cacheRest) {
this.freeCacheSpace(_scope, size);
}
cache[key] = val;
_scope.cacheStack.push({key: key, size: size});
_scope.cacheRest -= size;
}
return val;
},
getFromCache: function (key, scope) {
if (!!key) {
return this.getCache(scope)[key];
}
},
delFromCache: function (key, scope) {
var _scope = this.getCacheScope(scope),
cache = this.getCache(_scope),
stack = _scope.cacheStack;
if (!!key && cache[key]) {
delete cache[key];
_.each(stack, function (item, i) {
if (item.key === key) {
_scope.cacheRest += item.size;
stack = stack.splice(i, 1);
return;
}
});
}
return;
},
flushCache: function (scope) {
var _scope = this.getCacheScope(scope);
delete _scope.cache;
delete _scope.cacheRest;
delete _scope.cacheStack;
delete _scope.cacheSize;
return;
},
replace: function (a, b, c) {