RefreshCache fetches the latest version from npm and updates the local cache. No-op if the cache is still fresh (< 24h). Safe to call from a goroutine.
(currentVersion string)
| 92 | // RefreshCache fetches the latest version from npm and updates the local cache. |
| 93 | // No-op if the cache is still fresh (< 24h). Safe to call from a goroutine. |
| 94 | func RefreshCache(currentVersion string) { |
| 95 | if shouldSkip(currentVersion) { |
| 96 | return |
| 97 | } |
| 98 | state, _ := loadState() |
| 99 | if state != nil && time.Since(time.Unix(state.CheckedAt, 0)) < cacheTTL { |
| 100 | return // cache is fresh |
| 101 | } |
| 102 | latest, err := fetchLatestVersion() |
| 103 | if err != nil { |
| 104 | return |
| 105 | } |
| 106 | _ = saveState(&updateState{ |
| 107 | LatestVersion: latest, |
| 108 | CheckedAt: time.Now().Unix(), |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | func shouldSkip(version string) bool { |
| 113 | if os.Getenv("LARKSUITE_CLI_NO_UPDATE_NOTIFIER") != "" { |