@antv/data-wizard
Version:
A js/ts library for data processing
30 lines (29 loc) • 694 B
JavaScript
/**
* Cache some statistics to improve performance
*/
var CACHES = new WeakMap();
/**
* cache the value for target and key
* @param target - target
* @param key - key
* @param value - value
*/
export function set(target, key, value) {
// TODO: If target is object, the equal condition needs special handling
if (!CACHES.get(target)) {
CACHES.set(target, new Map());
}
CACHES.get(target).set(key, value);
return value;
}
/**
* get the cached value for target and key
* @param target - target
* @param key - key
*/
export function get(target, key) {
var cache = CACHES.get(target);
if (!cache)
return undefined;
return cache.get(key);
}