|
1 |
| -# Netlify Plugin: Custom Cache |
| 1 | +# ⚡ Netlify Plugin: Custom Cache [](https://www.npmjs.com/package/netlify-plugin-cache)  |
2 | 2 |
|
3 |
| -[](https://www.npmjs.com/package/netlify-plugin-cache) |
| 3 | +A generic cache plugin for saving and restoring files and/or folders between Netlify builds for impressive speed improvements. Worry less about running out of build minutes! ⏰ |
4 | 4 |
|
5 |
| -A generic cache plugin for saving and restoring files and/or folders between Netlify builds for impressive speed improvements. Worry less about running out of build minutes! ⚡ |
| 5 | +Essentially, this plugin is a pretty wrapper around [Netlify's native cache utility](https://github.com/netlify/build/blob/master/packages/cache-utils/README.md) — it isn't tied to any specific static site generator (on purpose). |
6 | 6 |
|
7 |
| -In other words, this plugin is a pretty wrapper around [Netlify's native cache utility](https://github.com/netlify/build/blob/master/packages/cache-utils/README.md |
8 |
| -) — it isn't tied to any specific static site generator (on purpose). |
| 7 | +## 💿 Install |
9 | 8 |
|
10 |
| -## Install |
11 |
| - |
12 |
| -Add the following to your `netlify.toml` configuration: |
| 9 | +Add the following lines to your `netlify.toml`: |
13 | 10 |
|
14 | 11 | ```toml
|
15 | 12 | [[plugins]]
|
16 | 13 | package = "netlify-plugin-cache"
|
17 | 14 | [plugins.inputs]
|
| 15 | + # Optional (but highly recommended). Defaults to [".cache"]. |
18 | 16 | paths = ["resources", "_vendor", "folder/file.md"]
|
19 | 17 | ```
|
20 | 18 |
|
21 |
| -This plugin only takes one input named `paths`, an array of files and/or directories relative to your project's root. These files/directories are restored before a build and saved in cache after a build **if it is successful**. |
| 19 | +This plugin only takes one input named `paths`: an array of files and/or directories relative to your project's root. These files/directories are restored before a build and saved in cache after a build **if it is successful**. |
22 | 20 |
|
23 |
| -**🚨 Important:** `paths` defaults to `[".cache"]`, but it's **highly recommended** you set this yourself based on the tools you're using. See examples below. |
| 21 | +**🚨 Important:** `paths` defaults to `[".cache"]`, but it's **highly recommended** you set this yourself based on the tool(s) you're using to generate your site. See examples below. |
24 | 22 |
|
25 | 23 | Read more about plugin configuration at [the official Netlify Plugin docs](https://docs.netlify.com/configure-builds/build-plugins/#install-a-plugin).
|
26 | 24 |
|
27 |
| -## Usage examples |
| 25 | +## 👩💻 Usage |
28 | 26 |
|
29 |
| -- **Hugo:** Caching the `resources` directory can speed up your build greatly if you [process](https://gohugo.io/content-management/image-processing/) a lot of images via Hugo pipes. You can also cache the `public` directory to avoid completely rebuilding the entire site on each deploy. [More info here.](https://gohugo.io/getting-started/directory-structure/#directory-structure-explained) |
| 27 | +- **Hugo:** Caching the `resources` directory can speed up your build greatly if you [process](https://gohugo.io/content-management/image-processing/) a lot of images, or compile SASS/SCSS via Hugo pipes. You can also cache the `public` directory to avoid completely rebuilding the entire site on each deploy. [More info here.](https://gohugo.io/getting-started/directory-structure/#directory-structure-explained) |
30 | 28 | - **Gatsby:** By default, the `.cache` directory holds persistent data between builds. You can also cache the `dist` directory to avoid completely rebuilding the entire site on each deploy. [More info here.](https://www.gatsbyjs.org/docs/build-caching/)
|
| 29 | +- **Jekyll:** A caching API was added as of v4. The notoriously slow SSG can become (relatively) faster by caching the `.jekyll-cache` directory. [More info here.](https://jekyllrb.com/tutorials/cache-api/) |
31 | 30 | - **Next.js:** The `.next` directory holds the build output. [More info here.](https://nextjs.org/docs/api-reference/next.config.js/setting-a-custom-build-directory)
|
32 |
| -- **Anything else:** This is the reason I kept this plugin as generic as possible! Research the caching behavior of your static site generator (and how to customize it if necessary). Feel free to make a PR and add it here as another example, too! |
| 31 | +- **Anything else:** This is the reason I kept this plugin as generic as possible! Research the caching behavior of your static site generator (and how to customize it if necessary). Feel free to open a PR and list it here as well! |
33 | 32 |
|
34 |
| -## Debugging |
| 33 | +## 🐛 Debugging |
35 | 34 |
|
36 | 35 | This plugin doesn't provide a way to output a list of files that were cached or restored, because Netlify already provides an official plugin named [`netlify-plugin-debug-cache`](https://github.com/netlify-labs/netlify-plugin-debug-cache) to do exactly that. No need to re-invent the wheel!
|
37 | 36 |
|
38 |
| -You can add their debug plugin **after** this plugin in your `netlify.toml`. (And yes, you need a `[[plugins]]` line for *each* plugin you add.) |
| 37 | +You can add the debug plugin **after** this plugin in your `netlify.toml`. (And yes, you need a `[[plugins]]` line for _each_ plugin you add.) |
39 | 38 |
|
40 | 39 | ```toml
|
41 | 40 | [[plugins]]
|
42 | 41 | package = "netlify-plugin-debug-cache"
|
43 | 42 | ```
|
44 | 43 |
|
45 |
| -The plugin will generate a file named `cache-output.json` at the root of your project's publish directory. [See an example file](https://gist.github.com/jakejarvis/dff606289e8b5d6be42d317e425bbee6#file-cache-output-json) or [learn more about this plugin](https://github.com/netlify-labs/netlify-plugin-debug-cache). |
| 44 | +The debug plugin will generate a file named `cache-output.json` at the root of your project's publish directory. [See an example file](https://infallible-wing-581e78.netlify.app/cache-output.json) or [learn more about this plugin](https://github.com/netlify-labs/netlify-plugin-debug-cache). |
46 | 45 |
|
47 |
| -## Licenses |
| 46 | +## 📜 License |
48 | 47 |
|
49 |
| -This project is distributed under the [MIT License](LICENSE). |
| 48 | +This project is distributed under the [MIT license](LICENSE). |
0 commit comments