(path string, ttl time.Duration)
| 265 | } |
| 266 | |
| 267 | func readModelsCache(path string, ttl time.Duration) ([]string, bool) { |
| 268 | if ttl <= 0 { |
| 269 | return nil, false |
| 270 | } |
| 271 | raw, err := os.ReadFile(path) |
| 272 | if err != nil { |
| 273 | return nil, false |
| 274 | } |
| 275 | var entry cacheEntry |
| 276 | if err := json.Unmarshal(raw, &entry); err != nil { |
| 277 | return nil, false |
| 278 | } |
| 279 | if entry.FetchedAt.IsZero() || time.Since(entry.FetchedAt) > ttl { |
| 280 | return nil, false |
| 281 | } |
| 282 | if len(entry.Models) == 0 { |
| 283 | return nil, false |
| 284 | } |
| 285 | return append([]string(nil), entry.Models...), true |
| 286 | } |
| 287 | |
| 288 | func writeModelsCache(path string, models []string) error { |
| 289 | if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { |
no test coverage detected