aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-07-16 01:56:37 +0200
committerGuillermo Serrahima <dev@vylion.com>2026-07-16 01:56:37 +0200
commitf0a7593dfa48a254f5a3664cd7ca80178d36f436 (patch)
treebf8d2a48bebc28c98b835c469a364021a156db80 /main.go
parente7a1d76f0562deaf990563394a1f6ede5cef4924 (diff)
downloadllostre-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.go28
1 files changed, 16 insertions, 12 deletions
diff --git a/main.go b/main.go
index adb0f91..e9a871e 100644
--- a/main.go
+++ b/main.go
@@ -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 == "" {