Skip to content

Commit

Permalink
Support asynchronous externals.localStorage API
Browse files Browse the repository at this point in the history
  • Loading branch information
SushilMallRC committed Jul 11, 2024
1 parent e28ac84 commit db37501
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sdk/src/core/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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<string[]> {
Expand Down

0 comments on commit db37501

Please sign in to comment.