mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 01:45:15 +00:00
22 lines
558 B
JavaScript
22 lines
558 B
JavaScript
|
// Used https://github.com/thinkloop/multi-key-cache as inspiration
|
||
|
const multiKeyStore = {
|
||
|
set: (cache, key1, key2, value) => {
|
||
|
let subCache = cache.get(key1);
|
||
|
|
||
|
if (!subCache) {
|
||
|
subCache = new Map();
|
||
|
cache.set(key1, subCache);
|
||
|
}
|
||
|
|
||
|
subCache.set(key2, value);
|
||
|
},
|
||
|
get: (cache, key1, key2) => {
|
||
|
const subCache = cache.get(key1);
|
||
|
return subCache ? subCache.get(key2) : undefined;
|
||
|
},
|
||
|
delete: (cache, key1, key2) => {
|
||
|
const subCache = cache.get(key1);
|
||
|
subCache.delete(key2);
|
||
|
}
|
||
|
};
|
||
|
export default multiKeyStore;
|