Skip to content

feat: add fast boolean is_cached / is_pipeline_cached, closes #1554#1559

Merged
xenova merged 1 commit intomainfrom
fix/remove-unnecessary-network-calls
Mar 5, 2026
Merged

feat: add fast boolean is_cached / is_pipeline_cached, closes #1554#1559
xenova merged 1 commit intomainfrom
fix/remove-unnecessary-network-calls

Conversation

@nico-martin
Copy link
Collaborator

Splits is_cached and is_pipeline_cached into two function pairs:

Function Returns
is_cached(modelId, options) Promise<boolean>
is_cached_files(modelId, options) Promise<CacheCheckResult>
is_pipeline_cached(task, modelId, options) Promise<boolean>
is_pipeline_cached_files(task, modelId, options) Promise<CacheCheckResult>

The boolean variants short-circuit on config.json: if that file is not cached, false is returned immediately without enumerating all model files.

Why two functions instead of an option flag

The alternative (is_cached(modelId, { detail: true })) was rejected because I dont like the idea of a function changing its return type based on a parameter value.
I know we do this at some places and yes, this can also be reflected in typesctipt types, but I still think having separate functions is a cleaner approach. This way its clear that _files returns the details for each file while the other just returns the boolean.
Separate functions keep types simple and make intent explicit at the call site.

Comment on lines +54 to +59
async function is_file_cached(modelId, filename, options = {}) {
const cache = await getCache(options?.cache_dir);
if (!cache) return false;
const { localPath, proposedCacheKey } = buildResourcePaths(modelId, filename, options, cache);
return !!(await checkCachedResource(cache, localPath, proposedCacheKey));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in future we could make this more efficient by supporting multiple file checks. for same built resource paths.

Would be useful for checking whether all the files needed for a pipeline (for example) are cached.

Luckily, not too much of an issue, and we can consider that in a a future PR (since this is how it works currently).

Copy link
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@xenova xenova merged commit f65a4c7 into main Mar 5, 2026
4 of 7 checks passed
@xenova xenova deleted the fix/remove-unnecessary-network-calls branch March 5, 2026 20:57
ysdede added a commit to ysdede/transformers.js that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants