diff --git a/cache.js b/cache.js new file mode 100644 index 0000000..eee3deb --- /dev/null +++ b/cache.js @@ -0,0 +1,20 @@ +class LRUCache { + #map = new Map; + #capacity; + constructor(capacity) { + this.#capacity = capacity; + } + get(key) { + if (!this.#map.has(key)) + return null; + const value = this.#map.get(key); + this.#map.delete(key); + this.#map.set(key, value); + return value; + } + put(key, value) { + while (this.#map.size >= this.#capacity) + this.#map.delete(this.#map.keys().next().value); + this.#map.set(key, value); + } +} diff --git a/webalign.html b/webalign.html index dd8d42f..ba63af1 100644 --- a/webalign.html +++ b/webalign.html @@ -128,6 +128,8 @@ + +