content icon indicating copy to clipboard operation
content copied to clipboard

Invalidate cache in production env when serving files from GitHub source

Open ManasMadrecha opened this issue 1 year ago • 7 comments

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

ManasMadrecha avatar Aug 28 '23 04:08 ManasMadrecha

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.

farnabaz avatar Aug 31 '23 12:08 farnabaz

@farnabaz @shareable-vision

~~Will solving #2260 solve this issue?~~

Edit: Will solving #2211 solve this issue?

ManasMadrecha avatar Sep 01 '23 06:09 ManasMadrecha

Did you mean #2211 with #2212?

nobkd avatar Sep 01 '23 06:09 nobkd

@nobkd Yes. 😁 Thanks for pointing these.

ManasMadrecha avatar Sep 01 '23 10:09 ManasMadrecha

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.

lysz210 avatar Jan 25 '24 20:01 lysz210

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

wesamjabali avatar Feb 15 '24 16:02 wesamjabali

@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.

feritarou avatar Jun 30 '24 13:06 feritarou