added cache invalidation

This commit is contained in:
specCon18 2025-06-19 21:09:56 -04:00
parent d848355256
commit 532d77a02d

15
main.go
View file

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