Skip to content

Commit eb2cfb1

Browse files
committed
store and rebuild cache from DB
1 parent 1f4d386 commit eb2cfb1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/portalnetwork/src/client/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ export class PortalNetwork extends EventEmitter<PortalNetworkEvents> {
298298
await this.discv5.start()
299299
await this.db.open()
300300
const storedIndex = await this.db.getBlockIndex()
301+
const storedEnrCache = await this.db.get('enr_cache')
302+
if (storedEnrCache) {
303+
this.enrCache = new Map(JSON.parse(storedEnrCache))
304+
}
301305
for (const network of this.networks.values()) {
302306
try {
303307
// Check for stored radius in db
@@ -334,6 +338,7 @@ export class PortalNetwork extends EventEmitter<PortalNetworkEvents> {
334338
await this.discv5.stop()
335339
this.discv5.removeAllListeners()
336340
this.removeAllListeners()
341+
await this.db.put('enr_cache', JSON.stringify([...this.enrCache.entries()]))
337342
await this.db.close()
338343
for (const network of this.networks.values()) {
339344
network.stopRefresh()

0 commit comments

Comments
 (0)