jlengstorf / netlify-plugin-gatsby-cache

185 stars 21 forks source link

Make it generic? #20

Closed slorber closed 4 years ago

slorber commented 4 years ago

Hi,

I'm trying to replace https://github.com/axe312ger/gatsby-plugin-netlify-cache with this plugin, but the gatsby plugin is more "generic" as it permits me to pass folders to cache as inputs.

Unfortunately, for my gatsby sites, we have a lot of images, and we did not choose to use Git LFS to handle them. Instead we sync images from S3 into a subfolder before building gatsby.

So I need to cache:

Unfortunately, this plugin does not permit me to add an extra folder, so I'd probably need to copy this plugin and tweak it as a local plugin to fit my need.

There's also a NextJS cache plugin here: https://github.com/pizzafox/netlify-cache-nextjs/blob/master/src/index.ts

What about making a generic cache plugin for Netlify to cover the caching needs of everybody, with a preset system for most common usecases?

I assume most sites/fwk will only need to do cache and restore from a list of paths, and nothing more. So presets can hardcode lists of paths, while inputs could allow to pass extra paths to cache/restore.

[[plugins]]
package = "netlify-plugin-cache"

    [plugins.inputs]
    preset = "gatsby"

       [[plugins.inputs.cacheFolders]]
       path = "./../s3images"

       [[plugins.inputs.cacheFolders]]
       path = "./../someDir"
jlengstorf commented 4 years ago

a generic build plugin is definitely possible! we introduced generic caching utils with the build plugins beta, so you could put together either a specific plugin to cache your images or a generic plugin that would operate on any configured directory

this plugin is scoped just to Gatsby’s generated files in the interest of zero-config installation

if you want to build a custom plugin, we'd love to see it and I'm happy to support as needed! setup details are in the build repo (https://github.com/netlify/build) and the cache utils are passed in to lifecycle methods like so: https://github.com/jlengstorf/netlify-plugin-gatsby-cache/blob/master/index.js#L12

I'm going to close this, but feel free to follow up here!

slorber commented 4 years ago

Thanks @jlengstorf

Not sure it's worth to make a generic plugin myself if it's not something officially supported. I've just used patch-package for now to add my extra folder.

Would you accept a PR to this plugin allowing to pass an extra folder as toml input?

jlengstorf commented 4 years ago

@slorber I'd prefer not to expand the responsibility of this plugin; your use case doesn't sound like a Gatsby caching concern, but rather a "something custom built on top of Gatsby" concern. that’s a perfectly valid thing to do, but I want to be extremely mindful of scope creep in this plugin because I have precious few hours and probably won't be able to keep up with issues related to custom directory caching

(that being said, you could duplicate this plugin and swap out the Gatsby directories for a user setting, which would give you a netlify-plugin-cache-anything that would work nicely alongside this plugin)

alternatively, maybe you could move your extra folders into .cache after build, rather than persisting additional directories?

slorber commented 4 years ago

Sure, my point is not to discuss if it's possible and how, but rather if I should invest my time on creating an extra package that nobody would use except me, or send a PR that won't be merged :)

I'm fine with patch-package for my usecase for now

jlengstorf commented 4 years ago

looks like a generic plugin was created! https://github.com/netlify/plugins/pull/83