feat: add fast boolean is_cached / is_pipeline_cached, closes #1554#1559
Merged
feat: add fast boolean is_cached / is_pipeline_cached, closes #1554#1559
is_cached / is_pipeline_cached, closes #1554#1559Conversation
xenova
reviewed
Mar 5, 2026
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)); | ||
| } |
Collaborator
There was a problem hiding this comment.
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).
ysdede
added a commit
to ysdede/transformers.js
that referenced
this pull request
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Splits
is_cachedandis_pipeline_cachedinto two function pairs: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,falseis 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
_filesreturns 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.