Static GitHub Issues

[1217] Global server cache

prev: required params in dynamic routes does not work in all cases
next: Nuxt link outer element

Hi, guys!

I'm using nuxt with express and I want to create global server cache for all requests. I can use lru-cache or something similar, but I don't know how to pass this data to nuxt.

For example, I have file data.js:

let data = undefined
function getData () {
  return new Promise(function (resolve, reject) {
    if (data) {
      resolve(data)
    } else {
      axios.get('/data')
        .then(response => {resolve(response.data)
        .catch(reject)})
    }
  }
}
module.exports = getData

If I add this file as a plugin, then it will be unique for every request, but how can add it as global?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1070">#c1070</a>)</em></sub></div>