import { bigintFrom } from "#utils"
export class Cache {
- static #storage: { [key: string]: string } = {}
- static #getItem (key: string): string | null {
- if (globalThis?.localStorage) return globalThis.localStorage.getItem(key)
- return this.#storage[key]
- }
- static #setItem (key: string, item: string): void {
- if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item)
- this.#storage[key] = item
+
+ static clear (): void {
+ this.#removeItem('NanoPowCache')
}
static search (hash: unknown, difficulty: bigint): WorkGenerateResponse | null {
this.#setItem('NanoPowCache', JSON.stringify(cache))
return result
}
+
+ static #storage: { [key: string]: string } = {}
+ static #getItem (key: string): string | null {
+ if (globalThis?.localStorage) return globalThis.localStorage.getItem(key)
+ return this.#storage[key]
+ }
+ static #removeItem (key: string): void {
+ if (globalThis?.localStorage) return globalThis.localStorage.removeItem(key)
+ this.#storage = {}
+ }
+ static #setItem (key: string, item: string): void {
+ if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item)
+ this.#storage[key] = item
+ }
}
//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
//! SPDX-License-Identifier: GPL-3.0-or-later
+import { Cache } from '.'
+export const clearCache = Cache.clear
+
export * from './api-support'
export * from './bigint'
export * from './cache'