(url string, kind entities.Kind, cache camconfig.CacheConfig)
| 295 | } |
| 296 | |
| 297 | func loadFromCache(url string, kind entities.Kind, cache camconfig.CacheConfig) (map[string]RepoEntry, error) { |
| 298 | path := cacheFilePath(url, kind, cache) |
| 299 | info, err := os.Stat(path) |
| 300 | if err != nil { |
| 301 | return nil, err |
| 302 | } |
| 303 | age := time.Since(info.ModTime()) |
| 304 | if age > time.Duration(cache.TTLSeconds)*time.Second { |
| 305 | return nil, fmt.Errorf("cache expired") |
| 306 | } |
| 307 | data, err := os.ReadFile(path) |
| 308 | if err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | return parseRepoJSON(data) |
| 312 | } |
| 313 | |
| 314 | func saveToCache(url string, kind entities.Kind, cache camconfig.CacheConfig, data []byte) error { |
| 315 | path := cacheFilePath(url, kind, cache) |
no test coverage detected