MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / readModelsCache

Function readModelsCache

internal/providers/models.go:267–286  ·  view source on GitHub ↗
(path string, ttl time.Duration)

Source from the content-addressed store, hash-verified

265}
266
267func 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
288func writeModelsCache(path string, models []string) error {
289 if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {

Callers 1

ResolveModelsFunction · 0.85

Calls 1

ReadFileMethod · 0.80

Tested by

no test coverage detected