mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-19 04:54:27 +01:00
Add an environment variable to disable the cache
This commit is contained in:
5
nostr.go
5
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user