From 532d77a02d857379686eefb6a5449761a14f7787 Mon Sep 17 00:00:00 2001 From: specCon18 Date: Thu, 19 Jun 2025 21:09:56 -0400 Subject: [PATCH] added cache invalidation --- main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index ca141b3..c884e13 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,17 @@ func getCachedUpdates(feedURL string) ([]Update, error) { return updates, nil } +func invalidateCache(w http.ResponseWriter, r *http.Request) { + cacheMu.Lock() + defer cacheMu.Unlock() + + cachedUpdates = nil + cacheExpiry = time.Time{} // zero time to force refresh on next request + + w.WriteHeader(http.StatusOK) + w.Write([]byte("Cache invalidated\n")) +} + func updatesHandler(w http.ResponseWriter, r *http.Request) { const feedURL = "https://steamdb.info/api/PatchnotesRSS/?appid=1874880" @@ -98,7 +109,9 @@ func updatesHandler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/updates", updatesHandler) - log.Println("Listening on http://localhost:8080/updates") + http.HandleFunc("/invalidate-cache", invalidateCache) + + log.Println("Listening on http://localhost:8080/") log.Fatal(http.ListenAndServe(":8080", nil)) }