Skip to content

Commit

Permalink
fix: caching getInfo calls (#2864)
Browse files Browse the repository at this point in the history
* fix: caching getInfo calls

* fix: add const for cache_key

* fix: cache check (is undefined)
  • Loading branch information
reneaaron authored Nov 15, 2023
1 parent c7194e9 commit e5eb4ef
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/extension/background-script/connectors/alby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class Alby implements Connector {
private config: Config;
private _client: Client | undefined;
private _authUser: auth.OAuth2User | undefined;
private _cache = new Map<string, object>();

constructor(account: Account, config: Config) {
this.account = account;
Expand Down Expand Up @@ -116,16 +117,27 @@ export default class Alby implements Connector {
async getInfo(): Promise<
GetInfoResponse<WebLNNode & GetAccountInformationResponse>
> {
const cacheKey = "getInfo";
const cacheValue = this._cache.get(cacheKey) as GetInfoResponse<
WebLNNode & GetAccountInformationResponse
>;
if (cacheValue) {
return cacheValue;
}

try {
const info = await this._request((client) =>
client.accountInformation({})
);
return {
const returnValue = {
data: {
...info,
alias: "🐝 getalby.com",
},
};
this._cache.set(cacheKey, returnValue);

return returnValue;
} catch (error) {
console.error(error);
throw error;
Expand Down

0 comments on commit e5eb4ef

Please sign in to comment.