Skip to content

Advanced caching of components, routes and data for Nuxt 3. Dynamically define CDN cache control headers. Provides cache management API for purging items by key or using cache tags.

License

Notifications You must be signed in to change notification settings

bgondy/nuxt-multi-cache

Repository files navigation

nuxt-multi-cache

SSR page, component and data cache for Nuxt. Supports purging cache entries by key or by cache tags.

Installation - Documentation - NPM

Concepts

  • Cache: Page, component and data with support for cache tags
  • Purge: Using cache tags or by key
  • Pick: Enable only what you need
  • Manage: REST API for purging and getting stats about the caches

Example

Cache a page with cache tags

<template>
  <div>
    <h1>Welcome!</h1>
  </div>
</template>

<script>
export default {
  asyncData({ app }) {
    return app.$api.get('article', { id: 10 }).then(article => {
      app.$cache.route.setCacheable()
      app.$cache.route.addTags(['article:10'])
      return { article }
    })
  },

  data() {
    return {
      article: {}
    }
  }
}
</script>

Purge a cached page

curl -X POST -i \
  -H "Authorization: Basic YWRtaW46aHVudGVyMgo=" \
  -H "Content-Type: application/json" \
  --data '["article:10"]' \
  http://localhost:3000/__nuxt_multi_cache/purge/tags

Warning

Caching is hard. You should be aware of the risks and potentially huge security issues that may arise when caching an entire page.

Always make sure to never cache anything with content restricted to authenticated users. Else you may leak sensitive information to anonymous users.

About

Advanced caching of components, routes and data for Nuxt 3. Dynamically define CDN cache control headers. Provides cache management API for purging items by key or using cache tags.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.3%
  • Vue 6.2%
  • JavaScript 0.5%