jen
June 9, 2020, 7:23pm
7
Hey @dbj and @dillonkearns ,
Our recommendation for custom cache handling is the cache
utility of our build plugins (now out of beta and in GA ):
Do you want to take a look at this plugin, which will likely be available in our UI shortly and is already available on npm, and see if it will work for the Elm cache?
netlify:main
← jakejarvis:add-netlify-plugin-cache
opened 04:07PM - 06 Jun 20 UTC
**Are you adding a plugin or updating one?**
- [x] Adding a plugin
- [ ] Upd… ating a plugin
**Have you completed the following?**
- [x] Read and followed the [plugin author guidelines](https://github.com/netlify/plugins/blob/master/docs/guidelines.md).
- [x] Included all [required fields](https://github.com/netlify/plugins/blob/master/docs/CONTRIBUTING.md#required-fields) in your entry.
- [x] Tested the plugin [locally](https://docs.netlify.com/cli/get-started/#run-builds-locally) and [on Netlify](https://docs.netlify.com/configure-builds/build-plugins/#install-a-plugin), using the plugin version stated in your entry.
**Test plan**
My [own Hugo site](https://github.com/jakejarvis/jarv.is) (see its [`netlify.toml` here](https://github.com/jakejarvis/jarv.is/blob/04ac760629473949d55179c7e153a724b92f95c8/netlify.toml#L41)) uses this plugin to cache the `resources` folder (with images processed/resized by Hugo, sometimes painfully slowly) and `_vendor` (cached Go modules). Successful deploy log here:
https://app.netlify.com/sites/jakejarvis/deploys/5edbba4109b2da00072a9f18
The plugin's readme [suggests different settings](https://github.com/jakejarvis/netlify-plugin-cache#usage-examples) for various SSGs. This is also linked to in the plugin output if the `paths` input refers to directories/files that don't exist — see the logs for a "failure" here (note the actual deploy **doesn't** fail):
https://app.netlify.com/sites/jakejarvis/deploys/5edbadf4787452f2795751b0
**More info**
Repo: https://github.com/jakejarvis/netlify-plugin-cache
NPM: https://www.npmjs.com/package/netlify-plugin-cache
I see a few great cache plugins already made for Hugo, Gatsby, Next.js, etc. but not a plugin that simply accepts an open-ended input allowing a user to cache whatever files/folders they want. This plugin does just that — basically a pretty wrapper around the [native `cache` util](https://github.com/netlify/build/blob/master/packages/cache-utils/README.md).
The plugin defaults to caching `[".cache"]` but can accept an array of any file(s) and/or folder(s) via the one input variable, `paths`. The [readme instructs users](https://github.com/jakejarvis/netlify-plugin-cache#debugging) to use the official [netlify-plugin-debug-cache](https://github.com/netlify-labs/netlify-plugin-debug-cache) plugin to list the contents of the cache for debugging/verification (no need to re-invent the wheel!), I've uploaded an [example of `cache-output.json` here](https://gist.github.com/jakejarvis/dff606289e8b5d6be42d317e425bbee6#file-cache-output-json) (after running this plugin).
I'm completely open to comments/suggestions if this isn't ready for the directory, or feel free to close if you think it's _too_ generic to be listed.
Thanks! 😊
1 Like