fix: cache update logic

This commit is contained in:
Carlos Alexandro Becker
2025-07-24 10:51:56 -03:00
parent 50f07eb229
commit 574ec2e850

View File

@@ -44,7 +44,7 @@ func providerCacheFileData() string {
}
func saveProvidersInCache(path string, providers []catwalk.Provider) error {
slog.Info("Caching provider data")
slog.Info("Saving cached provider data", "path", path)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return fmt.Errorf("failed to create directory for provider cache: %w", err)
}
@@ -94,13 +94,13 @@ func loadProviders(client ProviderClient, path string) (providerList []catwalk.P
// if cache is not stale, load from it
stale, exists := isCacheStale(path)
if !stale {
slog.Info("Using cached provider data")
slog.Info("Using cached provider data", "path", path)
providerList, err = loadProvidersFromCache(path)
if len(providerList) > 0 && err == nil {
go func() {
slog.Info("Updating provider cache in background")
updated, uerr := client.GetProviders()
if len(updated) == 0 && uerr == nil {
if len(updated) > 0 && uerr == nil {
_ = saveProvidersInCache(path, updated)
}
}()