Skip to content

Commit

Permalink
Merge pull request #265 from ringcentral/asyncSupport
Browse files Browse the repository at this point in the history
Support asynchronous externals.localStorage API
  • Loading branch information
SushilMallRC authored Jul 11, 2024
2 parents e28ac84 + ac33e42 commit 1722514
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/src/core/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class Cache {
}

public async setItem(key, data) {
this.setItemSync(key, data);
await this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data));
//this.setItemSync(key, data);
}

public removeItemSync(key) {
Expand All @@ -32,7 +33,8 @@ export default class Cache {
}

public async removeItem(key) {
await this.removeItemSync(key);
await this._externals.localStorage.removeItem(this._prefixKey(key));
//await this.removeItemSync(key);
}

public getItemSync(key) {
Expand All @@ -42,7 +44,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 1722514

Please sign in to comment.