(options: GetModelsOptions, refresh: boolean = false)
| 408 | * @param refresh - If true, immediately fetch fresh data from API |
| 409 | */ |
| 410 | export const flushModels = async (options: GetModelsOptions, refresh: boolean = false): Promise<void> => { |
| 411 | if (refresh) { |
| 412 | // Don't delete memory cache - let refreshModels atomically replace it |
| 413 | // This prevents a race condition where getModels() might be called |
| 414 | // before refresh completes, avoiding a gap in cache availability |
| 415 | // Await the refresh to ensure the cache is updated before returning |
| 416 | await refreshModels(options) |
| 417 | } else { |
| 418 | // Only delete memory cache when not refreshing. Use the compound cache key so that |
| 419 | // URL-scoped providers (litellm, poe, etc.) actually evict the per-server entry rather |
| 420 | // than a bare provider-name entry that was never written. |
| 421 | memoryCache.del(getCacheKey(options)) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Get models from cache, checking memory first, then disk. |
no test coverage detected