nuxtjs-drupal-ce icon indicating copy to clipboard operation
nuxtjs-drupal-ce copied to clipboard

Nuxt Caching Layer

Open StirStudios opened this issue 1 year ago • 1 comments

This might be something to consider on the nuxt side for caching: https://dev.to/ymir/mastering-caching-in-nuxt-3-a-comprehensive-guide-22ea

StirStudios avatar Apr 06 '24 02:04 StirStudios

I agree, that would be nice to support! In the end the change in server-routes to support it would be dead simple. Maybe we could just make our event handleres cached event handlers and expose some configuration options to adjust caching?

For the menu routes it makes a lot of sense to have some short-lived caches on by default imo, but we should watch out to vary caches by session cookie.

fago avatar Apr 30 '24 08:04 fago

@StirStudios Caching like described in the article is already the default behavior of Nuxt, if you enable the experimental.payloadExtraction option in Nuxt config.

From Nuxt docs:

getCachedData: Provide a function which returns cached data. A null or undefined return value will trigger a fetch. By default, this is:

const getDefaultCachedData = (key) => nuxtApp.isHydrating 
  ? nuxtApp.payload.data[key] 
  : nuxtApp.static.data[key]

Which only caches data when experimental.payloadExtraction of nuxt.config is enabled.

Source: useFetch.

TurtlBbx avatar Jan 21 '25 09:01 TurtlBbx