MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getCacheKey

Function getCacheKey

src/api/providers/fetchers/modelCache.ts:130–146  ·  view source on GitHub ↗

* Build a cache key that is unique per provider+server+key combination. * * - URL-scoped providers include the normalized baseUrl so that two different servers * of the same provider type never share a cache entry. * - Key-scoped providers additionally fold in a short, irreversible discriminat

(options: GetModelsOptions)

Source from the content-addressed store, hash-verified

128 * Requesty). See deriveApiKeyDiscriminator for why the value cannot be reversed to the key.
129 */
130function getCacheKey(options: GetModelsOptions): string {
131 const { provider } = options
132 const isUrlScoped = URL_SCOPED_PROVIDERS.has(provider as RouterName)
133 const isKeyScoped = KEY_SCOPED_PROVIDERS.has(provider as RouterName)
134
135 // Build URL and key components independently so that key-scoped providers
136 // without a custom baseUrl still get a per-key cache entry (otherwise two
137 // different keys on the default server would collapse to the same entry).
138 // Strip trailing slashes so "http://host:4000/" and "http://host:4000" map to the same key.
139 const urlPart = isUrlScoped && options.baseUrl ? options.baseUrl.replace(/\/+$/, "") : undefined
140 const keyPart = isKeyScoped && options.apiKey ? deriveApiKeyDiscriminator(options.apiKey) : undefined
141
142 if (urlPart && keyPart) return `${provider}:${urlPart}:${keyPart}`
143 if (urlPart) return `${provider}:${urlPart}`
144 if (keyPart) return `${provider}:${keyPart}`
145 return provider
146}
147
148/**
149 * Convert a cache key to a filesystem-safe filename component.

Callers 4

getModelsFunction · 0.70
refreshModelsFunction · 0.70
flushModelsFunction · 0.70
getModelsFromCacheFunction · 0.70

Calls 3

hasMethod · 0.65
replaceMethod · 0.65

Tested by

no test coverage detected