Adding a simple cache to keep track of points
This commit is contained in:
1 parent
2733906196
commit
7c09a5536a
4 files changed
+74
-1
No files matched your search
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
export const thisIsAModule = true;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
declare global {
|
||||
var _allCaches: any;
|
||||
}
|
||||
|
||||
globalThis._allCaches = new Map();
|
||||
|
||||
const cache = {
|
||||
set: (params: any) => {
|
||||
const { cacheId, key, value } = params;
|
||||
if (!_allCaches.has(cacheId)) {
|
||||
_allCaches.set(cacheId, new Map());
|
||||
}
|
||||
const k = _allCaches.get(cacheId);
|
||||
k.set(key, value);
|
||||
},
|
||||
get: (params: any) => {
|
||||
const { cacheId, key } = params;
|
||||
if (!_allCaches.has(cacheId)) {
|
||||
return null;
|
||||
}
|
||||
const k = _allCaches.get(cacheId);
|
||||
if (!k.has(key)) {
|
||||
return null;
|
||||
}
|
||||
const value = k.get(key);
|
||||
k.delete(key);
|
||||
k.set(key, value);
|
||||
return value;
|
||||
},
|
||||
delete: (params: any) => {
|
||||
const { cacheId, key } = params;
|
||||
if (!_allCaches.has(cacheId)) {
|
||||
return null;
|
||||
}
|
||||
const k = _allCaches.get(cacheId);
|
||||
if (!k.has(key)) {
|
||||
return null;
|
||||
}
|
||||
const value = k.get(key);
|
||||
k.delete(key);
|
||||
return value;
|
||||
},
|
||||
};
|
||||
|
||||
export default cache;
|
||||
Reference in new issue
Block a user