on main help sign in
fix: cache update logic
574ec2eCarlos Alexandro Becker
internal/config/provider.go+3−3
@@ -44,7 +44,7 @@ func providerCacheFileData() string {
44}
44}
45
45
46func saveProvidersInCache(path string, providers []catwalk.Provider) error {
46func saveProvidersInCache(path string, providers []catwalk.Provider) error {
47− slog.Info("Caching provider data")
47+ slog.Info("Saving cached provider data", "path", path)
48 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
48 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
49 return fmt.Errorf("failed to create directory for provider cache: %w", err)
49 return fmt.Errorf("failed to create directory for provider cache: %w", err)
50 }
50 }
@@ -94,13 +94,13 @@ func loadProviders(client ProviderClient, path string) (providerList []catwalk.P
94 // if cache is not stale, load from it
94 // if cache is not stale, load from it
95 stale, exists := isCacheStale(path)
95 stale, exists := isCacheStale(path)
96 if !stale {
96 if !stale {
97− slog.Info("Using cached provider data")
97+ slog.Info("Using cached provider data", "path", path)
98 providerList, err = loadProvidersFromCache(path)
98 providerList, err = loadProvidersFromCache(path)
99 if len(providerList) > 0 && err == nil {
99 if len(providerList) > 0 && err == nil {
100 go func() {
100 go func() {
101 slog.Info("Updating provider cache in background")
101 slog.Info("Updating provider cache in background")
102 updated, uerr := client.GetProviders()
102 updated, uerr := client.GetProviders()
103− if len(updated) == 0 && uerr == nil {
103+ if len(updated) > 0 && uerr == nil {
104 _ = saveProvidersInCache(path, updated)
104 _ = saveProvidersInCache(path, updated)
105 }
105 }
106 }()
106 }()