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

feat: add an optional cache that speeds up consecutive runs #38

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

sod
Copy link

@sod sod commented Feb 2, 2024

used like:

ngx-translate-extract --cache-file node_modules/.i18n-cache/my-cache-file --input ./src --output ./src/i18n/{da,en}.json
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In our project with 1100 scanned files, cached runs go down from 2 seconds to 0.3 seconds. And the terminal is less spamy as it only reports changed files.

The cache is implemented as careful as possible:

  • opt-in, so disabled by default (you need to provide --cache-file option)
  • the only thing that is cached is: "filename + contents" => "parser result"
  • removes entries from cache that were unused, to not let stale data linger
  • invalidate cache if package.json changes (aka new ngx-translate-extract release)
  • the globbing/search for files isn't cached, the extractor still looks at the entire project from scratch

But even if you don't use the cache, uncached is faster as well, as the .union calls that I removed shaved off half a second as well for us.

A cached run looks like this:
CleanShot 2024-02-02 at 14 55 20@2x

used like: ngx-translate-extract --cache-file node_modules/.i18n-cache/my-cache-file --input ./src --output ./src/i18n/{da,en}.json

In our project with 1100 scanned files, cached runs go down from 2 seconds to 0.3 seconds. And the terminal is less spamy as it only reports changed files.

The cache is implemented as careful as possible:
* opt-in, so disabled by default (you need to provide `--cache-file` option)
* always compares contents for a cache hit
* removes entries from cache that were not found, to not linger stale data
* invalidate cache if package.json changes (aka new ngx-translate-extract release)

But even if you don't use the cache, uncached is faster as well, as the `.union` calls that I removed shaved off half a second as well for us.
@michaelbromley michaelbromley merged commit 35af7eb into vendure-ecommerce:master Feb 5, 2024
4 checks passed
@michaelbromley
Copy link
Member

Thank you for this thorough implementation of a great new feature! I'll do a minor release which includes this.

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