class CacheData {
constructor(options) {
this.cacheData = new Map();
this.dataList = [];
this.cacheSize = options && options.cacheSize || 10000;
}
set(key, value) {
if (this.cacheData.size > this.cacheSize) {
const _key = this.dataList.shift();
this.delete(_key);
}
this.dataList.push(key);
this.cacheData.set(key, value);
}
delete(key) {
this.cacheData.delete(key);
const index = this.dataList.indexOf(key);
if (index !== -1) {
this.dataList.splice(index, 1);
}
}
get(key) {
return this.cacheData.get(key);
}
has(key) {
return this.cacheData.has(key);
}
clear() {
this.cacheData.clear();
this.dataList = [];
}
size() {
return this.cacheData.size;
}
}
export default CacheData;
import CacheData from '@/components/tools/extend/CacheData.js';
const module = new FdGlobal();
module.CacheData = CacheData;
window.fdGlobal = module;
this.requestCacheData = new window.fdGlobal.CacheData({
cacheSize: 10000
});