Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds createFsCache function for easier IO caching #306

Closed

Conversation

cspotcode
Copy link

When running multiple glob operations, I want to cache IO operations across all of them. The intuitive way to do this, at least for me, looks something like this:

// Create a cache that can be shared across all glob calls
const fsCache = glob.createFsCache();
const files1 = glob.sync('**/*.ts', {
  ...fsCache, // using object property spread
  cwd: 'src'
});
const files2 = glob.sync('**/*.{json,js}', Object.assign({ // using a helper function
  cwd: 'src/dependencies/button-widget'
}, fsCache));

I create a cache first and then pass it into each glob call.

Without a glob.createFsCache function, I would have to start the first glob operation, grab its caching options, and then pass those to subsequent glob calls. However, that's extra conditional logic and confusion that can be avoided.

Without a createFsCache function, my code has to do one or both of:

  • manually grab four properties off of a glob object: realpathCache, cache, symlinks, and statCache
  • Create those objects itself, knowing that they must be objects with a null prototype (this is undocumented)

If you think this is worth merging, I can add README documentation to this PR.

…tions, to be passed into multiple glob calls
@isaacs
Copy link
Owner

isaacs commented Mar 1, 2023

No longer an issue in v9, it uses PathScurry's built-in fs caching.

@isaacs isaacs closed this Mar 1, 2023
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