From db37501fdd40290a89b820e34f4ecd9451c28639 Mon Sep 17 00:00:00 2001 From: SushilMallRC Date: Thu, 11 Jul 2024 10:45:56 +0530 Subject: [PATCH] Support asynchronous externals.localStorage API --- sdk/src/core/Cache.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sdk/src/core/Cache.ts b/sdk/src/core/Cache.ts index 70e723f..e970b74 100644 --- a/sdk/src/core/Cache.ts +++ b/sdk/src/core/Cache.ts @@ -23,7 +23,9 @@ export default class Cache { } public async setItem(key, data) { - this.setItemSync(key, data); + await this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data)); + return this; + //this.setItemSync(key, data); } public removeItemSync(key) { @@ -32,7 +34,9 @@ export default class Cache { } public async removeItem(key) { - await this.removeItemSync(key); + await this._externals.localStorage.removeItem(this._prefixKey(key)); + return this; + //await this.removeItemSync(key); } public getItemSync(key) { @@ -42,7 +46,10 @@ export default class Cache { } public async getItem(key) { - return this.getItemSync(key); + const item = await this._externals.localStorage.getItem(this._prefixKey(key)); + if (!item) {return null;} + return JSON.parse(item); + // return this.getItemSync(key); } private async _keys(): Promise {