diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-21 13:46:10 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-21 13:46:10 +0800 |
| commit | 5205a76de15203655f9807578c8b5586f98a82bc (patch) | |
| tree | b22d0aeead6000d364a8bf1bb42516846b0a8b2b /brewcheck.go | |
| parent | 963b66e9e7047a188cc31319212d21a78cff49b0 (diff) | |
perf: cache stats for fasterlookup
Diffstat (limited to 'brewcheck.go')
| -rw-r--r-- | brewcheck.go | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/brewcheck.go b/brewcheck.go index d550db4..02546b1 100644 --- a/brewcheck.go +++ b/brewcheck.go @@ -4,20 +4,17 @@ import ( "fmt" "os" "os/exec" - "path/filepath" "time" - "github.com/adrg/xdg" "github.com/fatih/color" ) const TTL = 3 * 24 * time.Hour // 3 days +const cacheName = "brew-checked" func EnsureBrewAvailable() { - cache := filepath.Join(xdg.CacheHome, "wthis", "brew-checked") - // 1. check if cache file exists and is fresh - data, _ := os.ReadFile(cache) + data, _ := ReadCache(cacheName, TTL) t, _ := time.Parse(time.RFC3339, string(data)) if time.Since(t) < TTL { return @@ -32,6 +29,5 @@ func EnsureBrewAvailable() { } // 3. write cache - _ = os.MkdirAll(filepath.Dir(cache), 0o755) - _ = os.WriteFile(cache, []byte(time.Now().Format(time.RFC3339)), 0o644) + WriteCache(cacheName, []byte(time.Now().Format(time.RFC3339))) } |
