updated 缓存独立管理

This commit is contained in:
PASSER-BY 2022-12-09 20:58:44 +08:00
parent a90e5abb2f
commit da7bd9058f
5 changed files with 25 additions and 20 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

16
src/module/cache.js Normal file
View File

@ -0,0 +1,16 @@
/*
* 缓存数据
*/
import {modeData as _data} from './mode';
var _cache = {};
for(var key in _data){
_data[key].forEach(function(name){
if(typeof _cache[name]=='undefined'){
_cache[name] = [];
}
_cache[name].push(key);
});
}
export default _cache;

View File

@ -3,24 +3,23 @@
*/
import _map from './map';
var _cache = {}; // 模式缓存
var _mode = {}; // 模式缓存
var _data = Object.assign({},_map); // 最终数据
// 设置模式数据
export function setModeData(sign,data){
_cache[sign] = Object.assign(_cache[sign]||{},data);
_mode[sign] = Object.assign(_mode[sign]||{},data);
};
// 获取模式数据
export function getModeData(sign){
_data = Object.assign({},_map);
if(sign&&_cache[sign]){
for(var key in _cache[sign]){
_data[key] = [].concat(_cache[sign][key],_map[key]||[]);
if(sign&&_mode[sign]){
for(var key in _mode[sign]){
_data[key] = [].concat(_mode[sign][key],_map[key]||[]);
}
}
return _data;
};
// 获取数据
export {_data as modeData};

View File

@ -7,17 +7,7 @@ import _similar from './rule/similar';
import {zh2number} from './unit';
import {reverseId,filterId,getGenById} from './id';
import {modeData as _data} from './mode';
var _cache = {};
for(var key in _data){
_data[key].forEach(function(name){
if(typeof _cache[name]=='undefined'){
_cache[name] = [];
}
_cache[name].push(key);
});
}
import _cache from './cache';
// 获得最简
var getOptimal = function(options){