Gatsby: [.cache] Deleted file still shown in gatsby posts

Created on 10 Oct 2017  ·  34Comments  ·  Source: gatsbyjs/gatsby

I deleted a folder full of markdown in my src/pages directory but when I went to view my site (in dev) the folder was still being referenced. When I did a build the pages were still being referenced.

I did a grep search but nothing was found. I started wondering if some data was being save locally and I was correct. The .cache folder still had .json referencing the missing files as well as some file that I had updated to fix a typo (and the typo was still showing in development mode).

The fix was to delete the .cache folder. The real problem however is that the updates to the filesystem are not shown in gatsby in realtime which can cause discrepancies. What exactly can you tell us about this interesting bug?

question or discussion

Most helpful comment

To delete your .cache folder just, cd into your project folder and run this in shell:

rm -r ./.cache/*

To rebuild cache just run
gatsby develop or gatsby build

All 34 comments

Could you test if deleting a file works?

Perhaps this code here doesn't work when a folder is deleted not a file? https://github.com/gatsbyjs/gatsby/blob/74e3bd6179324e30fa7d0091ccd12146c3710e7d/packages/gatsby-source-filesystem/src/gatsby-node.js#L52

Still looking into this. Not stale!

Did this PR fix things for you? https://github.com/gatsbyjs/gatsby/pull/2546

Also having a similar issue. I modified my json file in project but everytime I build it is referencing stale data. I even tried to delete the .cache/json folder to no avail. Is there a way to clear the cache?

Updated to latest version 👍

To delete your .cache folder just, cd into your project folder and run this in shell:

rm -r ./.cache/*

To rebuild cache just run
gatsby develop or gatsby build

seems like it would help to have this as an arg to pass in, kind of like how docker does it:

gatsby develop --no-cache

It could also be helpful to have a gatsby clean command that cleans up the cache and whatever other cleanup is needed. Having this as a separate command would make it more discoverable through gatsby help

Creating then deleting caches makes the cache (more than) useless — instead — we need everyone to pitch in helping identify when and where our cache can get invalid. Our cache is already very good and can be perfect. We've merged ~10 PRs over the past 4-5 months fixing up edge cases in handling data in the cache e.g. this recent one https://github.com/gatsbyjs/gatsby/pull/4209

This particular issue was fixed a while ago actually so closing it now.

A general plea — if you ever run across a situation where you think the cache is at fault — please spend a bit of time verifying this it is a cache problem by verifying the problem and then create an issue with how to reproduce the problem, preferably with a sample site I or others could look at.

Caches are amazing and provide incredible speedups and improvements to the DX. Totally understand how annoying a cache is though if you don't feel you can trust it — but I've spent 100s of hours already on the cache and am perfectly willing to spend that much more to make it perfect. But need people's help to identify bugs so they can get fixed.

not having an official way to clean the cache until it's working well doesn't help the issue

An official way to clear the cache is a strong indication that the project doesn't care about making the cache good which is absolutely not the case. You should never clear the cache. Again, if you ever feel the need to clear the cache, please file an issue.

I'd love a way to reset the cache right now because I just switched one JPEG file for another with the same name, but for whatever reason, Gatsby doesn't see that the file has changed, and keeps showing the old image. It's driving me nuts because I can't figure out how to make it re-read the updated image file.

@timojaask where is the jpeg image being used? Is it referenced from a markdown file or are you querying it with graphql and ImageSharp?

@KyleAMathews I've got a graphql query with a lot of images, below is a snippet. So I changed the helsinki-basbas5.jpeg image from one to another with the same name.

export const query = graphql`
  query ArticleImages {
    basbas4: imageSharp(id: {regex: "/helsinki-basbas4/" }) {
      sizes(maxWidth: 700, maxHeight: 525, cropFocus: CENTER) {
        ...GatsbyImageSharpSizes
      }
    },
    basbas5: imageSharp(id: {regex: "/helsinki-basbas5/" }) {
      sizes(maxWidth: 700, maxHeight: 525, cropFocus: CENTER) {
        ...GatsbyImageSharpSizes
      }
    },
  }
`;

I noticed that if I change anything in the basbas5 query, it will show the updated image. For example, if I change cropFocus to NORTH, it works. If I change it back to CENTER, it will show the old image again.

Huh, that's odd. Lemme look into that real quick.

I didn't make it far with my investigation but this is definitely a bug — we shouldn't be caching any query results if the underlying data changes in some ways. We normally don't I believe so not entirely sure what's happening. I'd appreciate more people investigating.

Yes, I am storing markdown files, then deleting them, however the blog post rendered from the markdown file still persists on the webpage. Deleting .cache fixes this.

@KyleAMathews I too found the same issue with the images as @timojaask . In my case (fetching from Wordpress API), if I change an image on there, it seems the GraphQL isn't picking that up and still uses the old one, in both development and production (I suspect cache) as I build and deploy with aws cli. I have to manually go inside the GraphQL query, change something as to force it to re-do the query, and then it works.

Am I doing something wrong or is that just plan weird? The same happens with local images.

@filipetedim are you restarting gatsby develop? Gatsby doesn't know when you change data in WordPress so you need to trigger refetching data from there (which currently means restarting the develop server).

@KyleAMathews yep. Restarting develop and build too. It just doesn't pick it up unless I manually change something in the query. What I've done is every time this happens, I change the "quality" in the query to 99, then back to 100, then it successfully pulled it.

Same issue here. Trying to do another query using gatsby-source-strapi plugin, and neither the new fields that I created on Strapi, appeared. I already erased the .cache folder, browser cache, and whatever related to it, and nothing happens. The fields that I created aren't appearing.

Error:

TypeError: Cannot read property 'id' of null

Query:

{
  strapiLandingpage(Landing_Owner: {eq: "RemeCoin"}) {
    id
  }
}

The new field is Landing_Owner, and the return:

{
  "data": {
    "strapiLandingpage": null
  }
}

And, the data was previously created in Strapi database.

Someone could help?

Thanks!

@alexandresgf One simple way to make sure the cache is fresh is to rm -rf the entire project and re-clone it from git 😉 Make sure to push all changes before deleting! Works every time!

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub issues, we have to clean some of the old issues as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Gatsby version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Faced this issue today: swapped one png for another with the same name. SVG traces the new image, but the old one shows up, clipped to the size of the new one. Removing the cache didn't help, but changing the image name did.
chaika

I had the same problem as @timojaask. I am using the latest version of GatsbyJS. Resolved the issue by adding a suffix to my jpeg filename.

Having the same problem using source plugins, I have to delete the .cache folder after adding or removing any nodes for them to show up correctly.

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

Have a similar problem with svg files - I get the "info changed file at ...../file.svg but the actual webpage doesn't refresh - I have to stop gatsby develop and manually clear the .cache folder.

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

Thanks again for being part of the Gatsby community!

It’s been 30 days since
commented 11 days ago

Wait what?

Well... that's not right.

Sounds like some cachebusting might be the solution / workaround in general (hashes in generated file names and references).

I'm closing this issue, we fixed the problem described in this issue. When removing a md file, the listing gets removed but the html will still be accessible, which is described by https://github.com/gatsbyjs/gatsby/issues/10844.

If it's still an issue please open up a new issue.

I replaced an image with another that had the same name. Gatbsy kept showing the old one, even after removing the cache. I had to rename my image to make the change happen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  ·  3Comments

dustinhorton picture dustinhorton  ·  3Comments

jimfilippou picture jimfilippou  ·  3Comments

magicly picture magicly  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments