diff --git a/main.go b/main.go index 98b11fa..b1b2dc2 100644 --- a/main.go +++ b/main.go @@ -136,7 +136,7 @@ func getUpdatedData() (*Cache, error) { return nil, fmt.Errorf("failed to parse data as json: %v", err) } - cache := &Cache{UpdatedDate: time.Now()} + cache := &Cache{UpdatedDate: time.Now().Add(-time.Hour * 6)} // count the cases for i := range data[2] { @@ -163,7 +163,7 @@ func homePageHandler(w http.ResponseWriter, r *http.Request) { log.Printf("unable to serve page due to no cached data, possibly due to application still starting up, or AB government site down, or changed formatting - may need to review how page is parsed") return } - if time.Now().After(cache.UpdatedDate.Add(cacheTimeout)) { + if time.Now().Add(-time.Hour * 6).After(cache.UpdatedDate.Add(cacheTimeout)) { w.WriteHeader(http.StatusOK) tempCache, err := getUpdatedData() // Hold tempCache in case there's an error, we don't want to nullify our pointer to a working cache that has aged. We will proceed with aged data. if err != nil {