Cache flags #28331
Replies: 9 comments 24 replies
-
FYI, I'm enabling // gatsby-config.js
flags: {
FAST_DEV: true,
FAST_REFRESH: true,
}, info The following flags are active:
- FAST_DEV · Enable all experiments aimed at improving develop server start time
- FAST_REFRESH · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28390)) · Use React Fast Refresh instead of the legacy react-hot-loader for instantaneous feedback in your development server. Recommended for versions of React >= 17.0.
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
- LAZY_IMAGES · EXPERIMENTAL · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27603)) · Don't process images during development until they're requested from the browser. Speeds starting the develop server.
There are 2 other flags available that you might be interested in:
- PRESERVE_WEBPACK_CACHE · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28331)) · Don't delete webpack's cache when changing gatsby-node.js & gatsby-config.js files.
- PRESERVE_FILE_DOWNLOAD_CACHE · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28331)) · Don't delete the downloaded files cache when changing gatsby-node.js & gatsby-config.js files. |
Beta Was this translation helpful? Give feedback.
-
Nice call out in the CLI, it's a great way to discover those goodies. The instructions are not specific enough though. Not sure where to put flags.
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I've been having some issues on windows where it doesn't seem to preserve the download cache. I think it's due to how 'del' works. I've added in a line to not delete the caches folder and it appears to work.
I think this is sort of indicated by the documentation for del https://github.com/sindresorhus/del#beware I believe it is working for me because my builds are now faster if I have this change in my locally modified node_modules. |
Beta Was this translation helpful? Give feedback.
-
DescriptionWhen using
are emitted at build time. Steps to reproduceA minimal reproduction is available here Running Expected resultSuccessful build-time module resolution. Actual resultAn error at build time. Environmentconst flags = {
PRESERVE_WEBPACK_CACHE: true
};
|
Beta Was this translation helpful? Give feedback.
-
I got the "Hi from the Gatsby maintainers!" message about the PRESERVE_WEBPACK_CACHE flag in a CI build. Should I check the .cache folder into source control to take advantage of this? It's in my .gitignore but I'm not sure if I put it there or Gatsby did. |
Beta Was this translation helpful? Give feedback.
-
Can we have support for gatsby config files in I am using gatsby with ts-node and I get this error: Error: <w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve '/Users/phil/Code/newrade-core/packages/ze-design-website/gatsby-node.js' Also I tried to disable or modify the Relevant code is here: |
Beta Was this translation helpful? Give feedback.
-
Been a while since something was added to this discussion... But I still think there's a major issue with overly aggressive clearing of thumbnail cache for thumbnails generated by This was discussed here #24822 but then the issue was closed because part of the problem was addressed by Query on Demand and Lazy Image flags - but this only addresses the issue of slow dev server builds, the issue of production builds was not addressed. Ideally we could have something like PRESERVE_FILE_DOWNLOAD_CACHE but for image thumbnails. |
Beta Was this translation helpful? Give feedback.
-
Cache clearing
We're investigating ways to be smarter about clearing caches. Initial PR
Currently we delete the entire cache when your gatsby-node.js, gatsby-config.js, or package versions change or you run gatsby clean. This is unnecessarily aggressive — changing these things don't invalidate most caches. The current cache clearing behavior means very expensive operations like downloading and processing images have to be repeated quite often which makes iterating on the website a lot more frustrating than it should.
There are currently two cache clearing flags you can try:
PRESERVE_FILE_DOWNLOAD_CACHE
prevents file downloads from being deleted during cache clearing events (other thangatsby clean
which still deletes the entire cache).DEV_WEBPACK_CACHE
prevents the webpack cache from deleted duringgatsby develop
with the same caveat forgatsby clean
We will continue to clear other plugin caches e.g. those created by source & transformer plugins. We're looking at ways to safely making more selective clearing those caches as well.
To enable the new cache behavior, add to your gatsby-config.js:
These will also be enabled if you add the
FAST_DEV
flag which enables a number of WIP ways to speed up the dev server.Utilising webpack persistent caching
In addition to preserving webpack caches when invalidating gatsby cache,
PRESERVE_FILE_DOWNLOAD_CACHE
flag (sincegatsby@3.4.0
) also utilize webpack persitent caching for production builds. This makes webpack steps in subsequentgatsby build
significantly faster.Beta Was this translation helpful? Give feedback.
All reactions