sdk: only instantiate caches by default when they are necessary.

This commit is contained in:
fiatjaf
2025-02-11 14:14:48 -03:00
parent 7189cd7e02
commit 3de002aca1
5 changed files with 55 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"github.com/nbd-wtf/go-nostr"
cache_memory "github.com/nbd-wtf/go-nostr/sdk/cache/memory"
)
type Relay struct {
@@ -24,16 +25,28 @@ func (sys *System) FetchRelayList(ctx context.Context, pubkey string) GenericLis
}
func (sys *System) FetchBlockedRelayList(ctx context.Context, pubkey string) GenericList[RelayURL] {
if sys.BlockedRelayListCache == nil {
sys.BlockedRelayListCache = cache_memory.New32[GenericList[RelayURL]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10006, kind_10006, parseRelayURL, sys.BlockedRelayListCache)
return ml
}
func (sys *System) FetchSearchRelayList(ctx context.Context, pubkey string) GenericList[RelayURL] {
if sys.SearchRelayListCache == nil {
sys.SearchRelayListCache = cache_memory.New32[GenericList[RelayURL]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10007, kind_10007, parseRelayURL, sys.SearchRelayListCache)
return ml
}
func (sys *System) FetchRelaySets(ctx context.Context, pubkey string) GenericSets[RelayURL] {
if sys.RelaySetsCache == nil {
sys.RelaySetsCache = cache_memory.New32[GenericSets[RelayURL]](1000)
}
ml, _ := fetchGenericSets(sys, ctx, pubkey, 30002, kind_30002, parseRelayURL, sys.RelaySetsCache)
return ml
}