gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core: actually cache d


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: actually cache denominations
Date: Wed, 06 Mar 2024 10:31:57 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new d10b46bff wallet-core: actually cache denominations
d10b46bff is described below

commit d10b46bffcef1599ba59538c69cc11499a852b4d
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Mar 6 10:31:52 2024 +0100

    wallet-core: actually cache denominations
---
 packages/taler-wallet-core/src/wallet.ts | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index b9d277cf0..8c9eee009 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -354,13 +354,15 @@ export async function getDenomInfo(
   denomPubHash: string,
 ): Promise<DenominationInfo | undefined> {
   const key = `${exchangeBaseUrl}:${denomPubHash}`;
-  const cached = wex.ws.denomCache[key];
+  const cached = wex.ws.lookupDenomCache(key);
   if (cached) {
     return cached;
   }
   const d = await tx.denominations.get([exchangeBaseUrl, denomPubHash]);
   if (d) {
-    return DenominationRecord.toDenomInfo(d);
+    const denomInfo = DenominationRecord.toDenomInfo(d);
+    wex.ws.putDenomCache(key, denomInfo);
+    return denomInfo;
   }
   return undefined;
 }
@@ -1647,8 +1649,7 @@ export class InternalWalletState {
 
   initCalled = false;
 
-  // FIXME: Use an LRU cache here.
-  denomCache: Record<string, DenominationInfo> = {};
+  private denomCache: Map<string, DenominationInfo> = new Map();
 
   /**
    * Promises that are waiting for a particular resource.
@@ -1675,6 +1676,17 @@ export class InternalWalletState {
     return this._db;
   }
 
+  lookupDenomCache(denomCacheKey: string): DenominationInfo | undefined {
+    return this.denomCache.get(denomCacheKey);
+  }
+
+  putDenomCache(denomCacheKey: string, denomInfo: DenominationInfo): void {
+    if (this.denomCache.size > 1000) {
+      this.denomCache.clear();
+    }
+    this.denomCache.set(denomCacheKey, denomInfo);
+  }
+
   initWithConfig(newConfig: WalletRunConfig): void {
     if (this._config) {
       throw Error("config already set");

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]