Add an environment variable to disable the cache

This commit is contained in:
Daniele Tonon
2023-07-12 11:45:53 +02:00
parent d734b189d9
commit e03b522554
2 changed files with 8 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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()
}