added cache invalidation
This commit is contained in:
parent
d848355256
commit
532d77a02d
1 changed files with 14 additions and 1 deletions
15
main.go
15
main.go
|
|
@ -81,6 +81,17 @@ func getCachedUpdates(feedURL string) ([]Update, error) {
|
||||||
return updates, nil
|
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) {
|
func updatesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
const feedURL = "https://steamdb.info/api/PatchnotesRSS/?appid=1874880"
|
const feedURL = "https://steamdb.info/api/PatchnotesRSS/?appid=1874880"
|
||||||
|
|
||||||
|
|
@ -98,7 +109,9 @@ func updatesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/updates", updatesHandler)
|
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))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue