diff --git a/main.go b/main.go index a2ef6f2..2bf3874 100644 --- a/main.go +++ b/main.go @@ -43,19 +43,9 @@ func main() { var id uint32 = 29932586 data, ok := cache[id] - if !ok { - log.Printf("Fetching fresh data for %d\n", id) - s := godestone.NewScraper(bingode.New(), godestone.EN) - - c, err := s.FetchCharacter(id) - if err != nil { - log.Fatalln(err) - } - - raw_data, _ := json.Marshal(c.ClassJobs) - data = CacheRecord{Time: time.Now(), Data: string(raw_data)} - - cache[id] = data + if !ok || time.Now().After(data.Time.Add(time.Minute*10)) { + cache[id] = refetch_data(id) + data = cache[id] } cache_as_stored, err := json.Marshal(cache) @@ -69,3 +59,16 @@ func main() { } fmt.Printf("%s\n", data.Data) } + +func refetch_data(id uint32) CacheRecord { + log.Printf("Fetching fresh data for %d\n", id) + s := godestone.NewScraper(bingode.New(), godestone.EN) + + c, err := s.FetchCharacter(id) + if err != nil { + log.Fatalln(err) + } + + raw_data, _ := json.Marshal(c.ClassJobs) + return CacheRecord{Time: time.Now(), Data: string(raw_data)} +}