Skip to content

Commit

Permalink
store and rebuild cache from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Feb 3, 2025
1 parent 1f4d386 commit eb2cfb1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/portalnetwork/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ export class PortalNetwork extends EventEmitter<PortalNetworkEvents> {
await this.discv5.start()
await this.db.open()
const storedIndex = await this.db.getBlockIndex()
const storedEnrCache = await this.db.get('enr_cache')
if (storedEnrCache) {
this.enrCache = new Map(JSON.parse(storedEnrCache))
}
for (const network of this.networks.values()) {
try {
// Check for stored radius in db
Expand Down Expand Up @@ -334,6 +338,7 @@ export class PortalNetwork extends EventEmitter<PortalNetworkEvents> {
await this.discv5.stop()
this.discv5.removeAllListeners()
this.removeAllListeners()
await this.db.put('enr_cache', JSON.stringify([...this.enrCache.entries()]))
await this.db.close()
for (const network of this.networks.values()) {
network.stopRefresh()
Expand Down

0 comments on commit eb2cfb1

Please sign in to comment.