modelsCacheFile derives a stable, collision-resistant cache path from the provider name and the full request URL. The URL is hashed so a provider that changes its endpoint does not read a stale entry from the old one.
(dir, providerName, fullURL string)
| 41 | // provider name and the full request URL. The URL is hashed so a provider that |
| 42 | // changes its endpoint does not read a stale entry from the old one. |
| 43 | func modelsCacheFile(dir, providerName, fullURL string) string { |
| 44 | sum := sha256.Sum256([]byte(fullURL)) |
| 45 | slug := cacheNameSanitizer.ReplaceAllString(providerName, "_") |
| 46 | name := fmt.Sprintf("%s-%s.json", slug, hex.EncodeToString(sum[:])[:12]) |
| 47 | return filepath.Join(dir, name) |
| 48 | } |
| 49 | |
| 50 | // readModelsCache returns the cached model list for (providerName, fullURL). |
| 51 | // When maxAge > 0 the entry must be younger than maxAge; maxAge <= 0 accepts an |
no outgoing calls