nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.07k stars 623 forks source link

Invalidate cache in production env when serving files from GitHub source #2260

Open ManasMadrecha opened 1 year ago

ManasMadrecha commented 1 year ago

Environment

.

Reproduction

I'm using a private GitHub repo as my source for Content module.

The app is a server app, i.e., Nitro app deployed on on Firebase Cloud Functions.

I have created a file server/api/abc.ts wherein it fetches from serverQueryContent. It serves the docs so fetched. It also has a simple Firebase authentication check, i.e., if the request header has a Authorization Bearer token, then serve the docs with x query, else serve with y query.

In frontend vue page, I am using this api to fetch, i.e.,

## /pages/index.vue

const {data} = await useFetch('api/abc')

Describe the bug

When I update the contents on my GitHub repo, the deployed production app should serve the updated version, i.e., it should automatically fetch the newer version of GitHub repo.

However, even on refreshing the page, it serves from the cached version of the repo files as on the time of running npm run build. I waited for 10 minutes, as it is the default TTL in unstorage module, but to no avail.

Note: the authentication guard is working on the server api, i.e., the page shows x query if someone is logged in and as soon as the person logs out, y query is automatically shown. So the api is updating itself. But the api is not fetching the newer GitHub repo, but I think it is fetching from the cache.<integritynumber].json file even in production env.

Additional context

No response

Logs

No response

farnabaz commented 1 year ago

In production, the Module does not revalidate its cache, and it always uses built time cache. This feature might introduce in next release under an experimental flag, and currently there is no standard solution for it.

ManasMadrecha commented 1 year ago

@farnabaz @shareable-vision

Will solving #2260 solve this issue?

Edit: Will solving #2211 solve this issue?

nobkd commented 1 year ago

Did you mean #2211 with #2212?

ManasMadrecha commented 1 year ago

@nobkd Yes. 😁 Thanks for pointing these.

lysz210 commented 7 months ago

I'm trying to implement a dynamodb driver for nuxt content. I make it work in local but the build application never call dynamo. I tryed implementing nitro storage and used it without nuxt/content and workes. After checking code I found this: https://github.com/nuxt/content/blob/f9a155ff37c0ccb95e511452bea7472b364bbe5a/src/runtime/server/storage.ts#L143


  const cached: any = await cacheParsedStorage.getItem(id)
  if (isProduction && cached) {
    return cached.parsed
  }

  const meta = await sourceStorage.getMeta(id)
  const mtime = meta.mtime

For what I can tell if isProduction it always returns the cached content and never try to get meta for eventual newest. For me it should be enough to add a parameter to H3Event and change to if (event.dynamicContent && isProduction && cached) {. I'll try to fork and implement it.

wesamjabali commented 7 months ago

I'm also running into this problem. The buildtime cache makes nuxt content unusable with non-fs drivers.

feritarou commented 2 months ago

@lysz210 Did you manage to get a fork working? I'd be very interested to hear about your experience given that neither this issue nor the related #2212 seem to be progressing recently.