Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Cache isn’t available to deploy previews #480

Closed
jlengstorf opened this issue May 4, 2020 · 12 comments
Closed

Cache isn’t available to deploy previews #480

jlengstorf opened this issue May 4, 2020 · 12 comments
Assignees

Comments

@jlengstorf
Copy link

I am creating and caching a file and getting confirmation from the utils that it was cached, but it's not there on subsequent pushes to that PR

this log shows a cache miss, despite confirmation that the cache was created in the previous deploy (you can see the confirmation again, as well as a quick read of the file contents to make sure they're actually there, in the bottom of this log)
https://app.netlify.com/sites/modest-murdock-9912c4/deploys/5eae49da1063950007a54613

source code: https://github.com/jlengstorf/netlify-plugin-applitools-demo/tree/feat/netlify-plugin-high-five/netlify-plugin-en-corg-agement

@ehmicky ehmicky self-assigned this May 4, 2020
@erquhart
Copy link

@ehmicky any thoughts on this one?

@vbrown608
Copy link
Contributor

vbrown608 commented May 12, 2020

@jlengstorf does this have something to do with deploy previews in particular? Or is it that in general utils.cache is failing to cache and subsequently load the file?

Nevermind, I looked at jlengstorf/netlify-plugin-gatsby-cache#22 and I see that it's particular to deploy preview builds.

@ehmicky
Copy link
Contributor

ehmicky commented May 13, 2020

I remember some discussions about caching in deploy previews having non-intuitive behavior at times (outside of Build plugins or the cache utility). If I remember, this discussion was with @fool, but I am not completely sure. @fool Are you aware of anything specific about caching in deploy previews?

@fool
Copy link
Contributor

fool commented May 13, 2020

the issue I keep raising is this one:

https://github.com/netlify/buildbot/issues/575

...which is only about the FIRST build of any PR. Subsequent builds seem to me to have (correct) cache, and I think Support would have heard about it if the cache was never available to subsequent PR builds.

@ehmicky
Copy link
Contributor

ehmicky commented May 13, 2020

Thanks for pointing this out @fool.
I will investigate this bug.

@vbrown608
Copy link
Contributor

vbrown608 commented May 18, 2020

I did some testing on this, and it's only impacting caching within Netlify Build - additional node modules, for instance, are cached successfully in deploy preview builds. Also verified that it's not an issue for other non-master builds (ie branch builds).

Once the file is cached successfully (for example during a branch build), it's can be loaded successfully in a deploy preview build. So, the problem seems to be with saving.

I'm not really sure how the context might be interacting with caching for Netlify Build alone.

@ehmicky
Copy link
Contributor

ehmicky commented May 29, 2020

@earthboundkid
Copy link

According to the Debug Cache Plugin, my cache is not being shared between builds on a deploy branch. See spotlightpa/poor-richard#104. (Parcel, like Gatsby, use the .cache directory.)

@ehmicky ehmicky assigned erezrokah and unassigned ehmicky Jun 1, 2020
@vbrown608
Copy link
Contributor

I believe this is happening on the API side - @erezrokah pointed me in the right direction. We track a list of branches we've got a cache for. If some build of a branch (either triggered by a branch deploy or a deploy preview) has an existing cache, we use it. Otherwise we fall back to the cache for the master branch. However, we only update the list of "branches with an existing cache" on branch deploys.

So, when I saw the node_modules correctly cached during a deploy preview in my report above, it was happening because there had previously (several commits ago) been a branch deploy of that branch.

The node_modules weren't actually cached during the earlier branch deploy, but it caused us to add the branch to our list of branches that we should store a dedicated cache for.

In the deploy previews here you can see that node_modules is not successfully cached because there's never been a deploy preview of that branch.

@ricokahler
Copy link

If the cache doesn't currently work in the deploy preview, can we document that somewhere in the site or in the READMEs?

It's totally fine if that's the way it works, but I just spent my whole day trying to debug why the build cache wasn't working just to find out it was because the cache doesn't work in the deploy preview 😅

@eps1lon
Copy link

eps1lon commented Oct 8, 2020

What I'm currently not understanding is why we're able to set a digest for saving but not restoring. How does netlify even determine which cache to use? In all CI providers with caching I'm familiar with you have a single "cache"-task with a digest that can contain strings and files. The CI provider then uses this for saving and restoring. I should be able to do the same (Azure cache, CircleCI cache, GitHub cache)

The reason why you can usually hard code strings is if you have cache "evolutions" where you simply want to avoid cache sharing for one reason or another. The you go from cache-v1 to cache-v2 and are done.

Right now it's not apparent how netlify is determining if it should re-use a cache or not. By making this behavior configurable or at least transparent we'd probably be able to figure out why netlify is sometimes not caching deploy previews.

On a personal note: Caching for deploy previews is way more important for OSS packages than it is for branch deploys. The number of deploys we get from deploy previews is easily a magnitude bigger than that of production deploys. It's also the situation where you want the lowest response time between push and ready deploy.

@kaganjd
Copy link

kaganjd commented Nov 13, 2020

Netlify Support here 👋🏻 Exciting update: this has been fixed 🎉

Check out the community post for more details: https://community.netlify.com/t/build-cache-is-now-updated-in-deploy-preview-builds/26344

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants