From ac461a104d68aa8d9cca996cb8d625cf8bf507a6 Mon Sep 17 00:00:00 2001 From: Slincnik Date: Mon, 16 Dec 2024 17:41:11 +0300 Subject: [PATCH] feat: added cache adapter --- src/adapters/cache/ICacheAdapter.js | 9 +++++++++ src/adapters/cache/MapCache.js | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/adapters/cache/ICacheAdapter.js create mode 100644 src/adapters/cache/MapCache.js diff --git a/src/adapters/cache/ICacheAdapter.js b/src/adapters/cache/ICacheAdapter.js new file mode 100644 index 00000000..e4c49adc --- /dev/null +++ b/src/adapters/cache/ICacheAdapter.js @@ -0,0 +1,9 @@ +export default class ICacheAdapter { + get() {} + + set() {} + + clear() {} + + delete() {} +} diff --git a/src/adapters/cache/MapCache.js b/src/adapters/cache/MapCache.js new file mode 100644 index 00000000..63e57426 --- /dev/null +++ b/src/adapters/cache/MapCache.js @@ -0,0 +1,24 @@ +import ICacheAdapter from "./ICacheAdapter"; + +export default class MapCache extends ICacheAdapter { + constructor() { + super(); + this.store = new Map(); + } + + get(key) { + return this.store.get(key); + } + + set(key, value) { + this.store.set(key, value); + } + + clear() { + this.store.clear(); + } + + delete(key) { + this.store.delete(key); + } +}