MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / writeModelsCache

Function writeModelsCache

internal/plugins/ai/openai/models_cache.go:78–95  ·  view source on GitHub ↗

writeModelsCache persists a successfully fetched model list. Empty lists are not cached so a transient empty response does not stick for the whole TTL.

(providerName, fullURL string, models []string)

Source from the content-addressed store, hash-verified

76// writeModelsCache persists a successfully fetched model list. Empty lists are
77// not cached so a transient empty response does not stick for the whole TTL.
78func writeModelsCache(providerName, fullURL string, models []string) error {
79 if len(models) == 0 {
80 return nil
81 }
82 dir, err := modelsCacheDir()
83 if err != nil {
84 return err
85 }
86 if err := os.MkdirAll(dir, 0o755); err != nil {
87 return err
88 }
89 entry := modelsCacheEntry{URL: fullURL, FetchedAt: time.Now(), Models: models}
90 data, err := json.Marshal(entry)
91 if err != nil {
92 return err
93 }
94 return os.WriteFile(modelsCacheFile(dir, providerName, fullURL), data, 0o600)
95}

Calls 1

modelsCacheFileFunction · 0.85