diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-07-16 01:56:37 +0200 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-07-16 01:56:37 +0200 |
| commit | f0a7593dfa48a254f5a3664cd7ca80178d36f436 (patch) | |
| tree | bf8d2a48bebc28c98b835c469a364021a156db80 /main.go | |
| parent | e7a1d76f0562deaf990563394a1f6ede5cef4924 (diff) | |
| download | llostre-f0a7593dfa48a254f5a3664cd7ca80178d36f436.tar.xz llostre-f0a7593dfa48a254f5a3664cd7ca80178d36f436.zip | |
Split note and author TTLs; added TTL refresh on cache access
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -63,21 +63,12 @@ func init() { logger.Debug("Logging configured", "log level", logLevel) slingshotURL := os.Getenv("SLINGSHOT_URL") - ttlMin := os.Getenv("TTL_MIN") + postExpiryMinutes := parseTTLMinutes("POST_TTL_MIN", 4320) + profileExpiryMinutes := parseTTLMinutes("PROFILE_TTL_MIN", 10080) - var expiryMinutes int - if ttlMin != "" { - var err error - expiryMinutes, err = strconv.Atoi(ttlMin) - if err != nil { - panic(err) - } - } else { - expiryMinutes = 15 - } valkeyAddr := os.Getenv("VALKEY_ADDR") valkeyPassword := os.Getenv("VALKEY_PASSWORD") - postCache, err := fetchers.NewCache(valkeyAddr, valkeyPassword, expiryMinutes) + postCache, err := fetchers.NewCache(valkeyAddr, valkeyPassword, postExpiryMinutes, profileExpiryMinutes) if err != nil { logger.Error("failed to connect to valkey", "error", err) panic(err) @@ -103,6 +94,19 @@ func init() { } } +func parseTTLMinutes(envVar string, defaultMinutes int) int { + raw := os.Getenv(envVar) + if raw == "" { + return defaultMinutes + } + + minutes, err := strconv.Atoi(raw) + if err != nil { + panic(err) + } + return minutes +} + func loginHandler(w http.ResponseWriter, r *http.Request) { handle := r.URL.Query().Get("handle") if handle == "" { |
