From e03b52255449a37bf9ea0fe7640920bfb4bf1134 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Wed, 12 Jul 2023 11:45:53 +0200 Subject: [PATCH] Add an environment variable to disable the cache --- nostr.go | 5 ++++- render.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nostr.go b/nostr.go index 23e9599..ed47382 100644 --- a/nostr.go +++ b/nostr.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "os" "time" "github.com/dgraph-io/ristretto" @@ -120,7 +121,9 @@ func getEvent(ctx context.Context, code string) (*nostr.Event, error) { ctx, cancel := context.WithTimeout(ctx, time.Second*8) defer cancel() for event := range pool.SubManyEose(ctx, relays, nostr.Filters{filter}) { - cache.SetWithTTL(code, event, 1, time.Hour*24*7) + if (os.Getenv("DISABLE_CACHE") != "yes") { + cache.SetWithTTL(code, event, 1, time.Hour*24*7) + } return event, nil } diff --git a/render.go b/render.go index 996d88a..be1967f 100644 --- a/render.go +++ b/render.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "regexp" "strings" "time" @@ -76,7 +77,9 @@ func render(w http.ResponseWriter, r *http.Request) { } else { ctx, cancel := context.WithTimeout(r.Context(), time.Second*4) lastNotes = getLastNotes(ctx, code) - cache.SetWithTTL(key, lastNotes, int64(len(lastNotes)), time.Hour*24) + if (os.Getenv("DISABLE_CACHE") != "yes") { + cache.SetWithTTL(key, lastNotes, int64(len(lastNotes)), time.Hour*24) + } cancel() }