Fixed cache localstorage
All checks were successful
Build / Build NPM Project (push) Successful in 37s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 34s

This commit is contained in:
Zakary Timson 2024-10-14 20:04:29 -04:00
parent 494cfaaccd
commit 1af23ac544
2 changed files with 3 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.20.0", "version": "0.20.1",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@ -95,7 +95,7 @@ export class Cache<K extends string | number | symbol, T> {
delete(key: K) { delete(key: K) {
delete this.store[key]; delete this.store[key];
if(this.options.storageKey && this.options.storage) if(this.options.storageKey && this.options.storage)
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.cache)); this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
} }
/** /**
@ -144,7 +144,7 @@ export class Cache<K extends string | number | symbol, T> {
set(key: K, value: T, ttl = this.options.ttl): this { set(key: K, value: T, ttl = this.options.ttl): this {
this.store[key] = value; this.store[key] = value;
if(this.options.storageKey && this.options.storage) if(this.options.storageKey && this.options.storage)
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.cache)); this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
if(ttl) setTimeout(() => { if(ttl) setTimeout(() => {
this.complete = false; this.complete = false;
this.delete(key); this.delete(key);