pastebin/js/cache.js
2019-09-22 00:01:42 +02:00

16 lines
342 B
JavaScript

export default class Cache {
constructor(initializer) {
this.elems = new Map
this.initializer = initializer
}
get(key) {
if (this.elems.has(key)) {
return this.elems.get(key)
}
const value = this.initializer(key)
this.elems.set(key, value)
return value
}
}